Skip to content

Conversation

@njroussel
Copy link
Member

This PR adds different strategies to handle virtual function calls.

Currently, in order to do a virtual function call in CUDA, we use indirect function calls to call either an OptiX direct callable or a CUDA function. Given that we know exactly the set of possible targets for any virtual function call, it is not necessary to have the indirection and we can explicitly call the appropriate target function.

This PR adds a new JitFlag, called VCallBranch which will replace the indirect function call by a series of branches to call the appropriate target function. There are three different branching strategies implemented:

  • Linear search: We lineraly compare against all possible target functions to determine the final/appropriate target. This is the default behaviour when enabling VCallBranch.
  • Binary search: The set of possible target functions is represented as a binary search tree, and the final target is computed by searching through. This strategy can be enabled by using the VCallBranchBinarySearch JIT flag.
  • Jump table: A jump table from the instance's callable index to all possible targets is used. This strategy can be enabled by using the VCallBranchJumpTable JIT flag

…ched by indirect function calls (CUDA) or direct callables (Optix) but converted into switch-like statements
…table rather than a series of individual branches.
…a binary search to branch to the appropriate vcall.
@njroussel njroussel requested review from Speierers and wjakob December 6, 2022 12:39
Copy link
Member

@Speierers Speierers left a comment

Choose a reason for hiding this comment

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

LGTM!

bool jump_table = jit_flag(JitFlag::VCallBranchJumpTable);
bool binary_search = jit_flag(JitFlag::VCallBranchBinarySearch);

if (jump_table == binary_search) {
Copy link
Member

Choose a reason for hiding this comment

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

I am intrigued by this condition. I suppose this could also be written as !jump_table && !binary_search? In the case where both are true we should throw an error no?

Comment on lines +838 to +842
if (jump_table)
jitc_log(Warn, "jitc_var_vcall_assemble_cuda(): both "
"JitFlag::VCallBranchJumpTable and "
"JitFlag::VCallBranchBinarySearch are enabled, "
"defaulting back to linear search!");
Copy link
Member

Choose a reason for hiding this comment

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

I see this now. Maybe we should throw an exception instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants