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

Fix Issue With Evaluating Varying Closure Keyword Parameters During Batched Evaluation #1620

Merged

Conversation

danieldresser-ie
Copy link
Contributor

When evaluating varying closure keyword parameters in batched execution, the value of the first lane in the batch would be used for the whole batch. More details in an issue I made here: #1619

I don't really understand this code at all, this fix was just made by following the suggestion of Stephen on the dev list to copy the code from llvm_gen_closure to llvm_gen_keyword_fill.

It fixes the one simple case which I've added a test for, but the more complex functionality of this code I copied would only be tested if you used array keyword parameters on a closure. This would be more annoying to test, since I don't think testshade declares any closures with array keyword parameters.

Also, while testing, I found a segfault with adding a null closure in batched evaluation - I'll post a repro for that on the dev list, and hopefully we can clean that up soon too.

  • I have read the contribution guidelines.
  • I have previously submitted a Contributor License Agreement.
  • I have updated the documentation, if applicable.
  • I have ensured that the change is tested somewhere in the testsuite (adding new test cases if necessary).
  • My code follows the prevailing code style of this project.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 16, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: danieldresser-ie (be73c33)

: NULL;
for (int c = 0; c < num_components; c++) {
llvm::Value* dest_elem;
if (num_components > 1)
Copy link
Contributor

@AlexMWells AlexMWells Nov 16, 2022

Choose a reason for hiding this comment

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

What happens for an array of of objects with 1 component?
Looks like maybe the else case is taken which disregards the "a" which is the element index.
Does the else case need to incorporate the arrayind or "a"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that does look like a bug to me too ... which quite possibly means it is also a bug on line 7243 where I copied the code from?

Not that I want to make it harder to get this quick fix I need over the line, but I do wonder if we should add a closure with more types of parameters to testshade so that it's possible to actually write testcases for this code.

Copy link
Contributor

Choose a reason for hiding this comment

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

This same comment might apply to the copy loop in llvm_gen_closure of batched_llvm_gen.cpp

Copy link
Contributor

Choose a reason for hiding this comment

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

Following the adage of "if its not tested its broken", yes being able to test these combinations would be a great idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This started out as a quick fix to a bug that was holding me up ... modifying testshade seems like a somewhat larger change - adding new closure parameters to testshade feels a bit more involved, since they would potentially be visible to other users of OSL. Does someone want to decide what this should look like? Should we add some keyword parameters to debug()? Oh, wait, looking at the list of macros in genclosure.h, it looks like keyword array parameters aren't currently supported anyway? So potentially I could drop the iteration code and use a simple memcpy - though the bug would still potentially exist in the non-keyword array parameter case that already exists. Should we add a special test closure with a parameter of every type in genclosure.h?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, that looks like a bug. I think the two main purposes of testshade are to provide an example of how to integrate the library and to allow for testing the important features of the library. A special 'test' closure which exercises the types in genclosure.h would be something that accomplishes both, so sounds like a good idea to me -- it'll keep me from accidentally checking things like this in that work for our renderer which doesn't make heavy use of closures but break those that depend on them heavily.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can still get this fix over the fence without everything else, maybe remove the array index stuff if you know its not needed, replace it with an assert? You have added a test case and modified source to allow it to pass without breaking any other testcases. We just noticed some other issues along the way. Maybe drop a "todo" on the line 7243 to add testcase and fix bug.

@danieldresser-ie
Copy link
Contributor Author

As per Alex's comment, I've removed support for array indexing, avoiding the bug he observed with the faulty array handling I copied. I wasn't able to get it working with one big memcpy ... unsure if this is due to not understanding the context well enough, or whether a per-component approach is required in order to get masking and such working. Anyway, I started from the other end, with the more complex code that worked, and removed the array handling but kept the component handling - this seems to have resulted in working code, and I've removed the array part, and added an assert that the arraylen is 0.

As for the bug at line 7243, I've added #1621 with a test case that demonstrates that bug - does it make sense to merge this and then continue that part of the conversation over there?

)

When evaluating varying closure keyword parameters in batched execution,
the value of the first lane in the batch would be used for the whole
batch.

Signed-off-by: Daniel Dresser <danield@image-engine.com>
Copy link
Contributor

@AlexMWells AlexMWells left a comment

Choose a reason for hiding this comment

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

Looks Great To Me

@lgritz lgritz merged commit 8530aa0 into AcademySoftwareFoundation:main Nov 23, 2022
lgritz pushed a commit to lgritz/OpenShadingLanguage that referenced this pull request Dec 20, 2022
) (AcademySoftwareFoundation#1620)

When evaluating varying closure keyword parameters in batched execution,
the value of the first lane in the batch would be used for the whole
batch.

Signed-off-by: Daniel Dresser <danield@image-engine.com>
lgritz pushed a commit to lgritz/OpenShadingLanguage that referenced this pull request Jan 3, 2023
) (AcademySoftwareFoundation#1620)

When evaluating varying closure keyword parameters in batched execution,
the value of the first lane in the batch would be used for the whole
batch.

Signed-off-by: Daniel Dresser <danield@image-engine.com>
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.

4 participants