Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All domain Registry Traversal per Backend #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DoeringChristian
Copy link
Contributor

@DoeringChristian DoeringChristian commented Oct 23, 2024

The PR adds the option to traverse all registry entries for a backend.

This is required for function freezing, as it is not easily possible to get the domains of a variable representing a pointer, when traversing a C++ class such as a scene.
The fix is to just traverse the whole registry.

This PR makes the following changes:

  • modifies the jitc_registry_id_bound function to return the bound over all domains in the backend if the domain argument is a nullptr
  • Adds a jitc_registry_fill_ptrs function, taking a pointer to a memory region to fill with the registered pointers.
  • Adds the backend as a field to the Domain struct

@DoeringChristian
Copy link
Contributor Author

@wjakob, @merlinND This PR should be ready for review.

Copy link
Member

@merlinND merlinND left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this one easy to review as well!

extern JIT_EXPORT uint32_t jit_registry_id_bound(JitBackend backend,
const char *domain);

/// Fills the \c dest pointer array with all pointers registered in the registry
/// \c dest has to point to an array with \c jit_registry_id_bound(backend, nullptr) entries
extern JIT_EXPORT void jit_registry_fill_ptrs(JitBackend backend, void **dest);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"fill_ptrs" could sound like you're filling the registry. Maybe jit_registry_all_pointers() or jit_registry_get_pointers()?

@@ -494,9 +494,14 @@ extern JIT_EXPORT void jit_registry_remove(const void *ptr);
extern JIT_EXPORT uint32_t jit_registry_id(const void *ptr);

/// Return the largest instance ID for the given domain
/// If the \c domain is a nullptr, it returns the largest instance ID for the given backend
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it looks like it just counts the number of active entries in a domain, not the largest instance ID?

Comment on lines +156 to +157
for (Domain &domain : r.domains) {
if (domain.backend == backend)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you could create a DomainKey{ backend, domain_name } to look up the domain ID into r.domain_ids, but I don't think it would be faster than your current implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I guess it depends on how many domains there are with a different backend.

src/registry.cpp Outdated
@@ -149,13 +151,38 @@ uint32_t jitc_registry_id(const void *ptr) {

uint32_t jitc_registry_id_bound(JitBackend backend, const char *domain) {
Registry &r = registry;
if (!domain) {
uint32_t i = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint32_t i = 0;
uint32_t n = 0;

since it's a count and not an index.

src/registry.cpp Outdated
auto it = r.domain_ids.find(DomainKey{ backend, domain });
if (it == r.domain_ids.end())
return 0;
else
return r.domains[it->second].id_bound;
}

void jitc_registry_fill_ptrs(JitBackend backend, void **dest) {
Registry &r = registry;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Registry &r = registry;
const Registry &r = registry;

src/registry.h Outdated
@@ -22,8 +22,13 @@ extern void jitc_registry_remove(const void *ptr);
extern uint32_t jitc_registry_id(const void *ptr);

/// Return the largest instance ID for the given domain
/// If the \c domain is a nullptr, it returns the largest instance ID for the given backend
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

@merlinND merlinND added the enhancement New feature or request label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants