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

GPU string overhaul #1531

Merged
merged 4 commits into from
Jul 13, 2022
Merged

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented Jul 7, 2022

Big string cleanup, yet again, for GPU. We still had this tricky
double indirection happening with strings for OptiX -- the string was
a pointer to a "global", which in turn held the hash. No, throw all
that out. Just directly store strings as the ustring hash on
OptiX. No extra indirection. Many fewer differences between how things
are handled on OptiX versus CPU (except for the fact itself that the
"string" holds the hash rather than the char*).

Some details worth noting:

  • LLVM_Util loses "type_string()" and calls it "type_ustring()" to
    emphasize it's the type we're using to represent a ustring, and
    definitely not a C or C++std string. Also, LLVM_Util itself now lets
    the caller tell it whether it prefers that the representation of a
    ustring be the charptr or the hash, and then handles most of the
    details internally. The BackendLLVM, then, makes that decision early
    on, charptr for CPU and hash for GPU.

  • Several more spots in LLVM_Util and BackendLLVM have been plumbed to
    pass around llvm IR SSA variable names to try to make the resulting
    LLVM IR more readable when I'm trying to debug it. (This was
    strictly debugging scaffalding aid for me, but comes along for the
    ride because it's useful to keep.) I also added a
    BackendLLVM::llnamefmt to format strings, which only does the
    formatting when the shading system knows it's going to save the IR
    for inspection, and otherwise (that is, in production) it does not
    do the string formatting or pass the names along, so it's not doing
    all that string manipulation when no human is going to be looking at
    the IR dumps.

  • A lot of clunky OptiX-only code disappears.

  • Some side effects of my reducing complexity of the IR as I debugged:
    there were times we were generating redundant pointer casting in the
    IR, such as grabbing a pointer, then casting it to a void*, then
    casting back to some other kind of pointer. In some cases I reduced
    that quite a bit. Again, this was mostly just a scramble to make the
    IR more readable while I debugged, but it probably has a minor
    performance gain as well since it reduced somewhat the sheer amount
    of IR we generate and pass to the optimizer and JIT.

Signed-off-by: Larry Gritz lg@larrygritz.com

Big string cleanup, yet again, for GPU. We still had this tricky
double indirection happening with strings for OptiX -- the string was
a pointer to a "global", which in turn held the hash. No, throw all
that out.  Just directly store strings as the ustring hash on
OptiX. No extra indirection. Many fewer differences between how things
are handled on OptiX versus CPU (except for the fact itself that the
"string" holds the hash rather than the char*).

Some details worth noting:

* LLVM_Util loses "type_string()" and calls it "type_ustring()" to
  emphasize it's the type we're using to represent a ustring, and
  definitely not a C or C++std string. Also, LLVM_Util itself now lets
  the caller tell it whether it prefers that the representation of a
  ustring be the charptr or the hash, and then handles most of the
  details internally. The BackendLLVM, then, makes that decision early
  on, charptr for CPU and hash for GPU.

* Several more spots in LLVM_Util and BackendLLVM have been plumbed to
  pass around llvm IR SSA variable names to try to make the resulting
  LLVM IR more readable when I'm trying to debug it. (This was
  strictly debugging scaffalding aid for me, but comes along for the
  ride because it's useful to keep.) I also added a
  BackendLLVM::llnamefmt to format strings, which only does the
  formatting when the shading system knows it's going to save the IR
  for inspection, and otherwise (that is, in production) it does not
  do the string formatting or pass the names along, so it's not doing
  all that string manipulation when no human is going to be looking at
  the IR dumps.

* A lot of clunky OptiX-only code disappears.

* Some side effects of my reducing complexity of the IR as I debugged:
  there were times we were generating redundant pointer casting in the
  IR, such as grabbing a pointer, then casting it to a void*, then
  casting back to some other kind of pointer. In some cases I reduced
  that quite a bit. Again, this was mostly just a scramble to make the
  IR more readable while I debugged, but it probably has a minor
  performance gain as well since it reduced somewhat the sheer amount
  of IR we generate and pass to the optimizer and JIT.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz lgritz requested a review from cmstein July 7, 2022 18:21
@lgritz
Copy link
Collaborator Author

lgritz commented Jul 7, 2022

@timgrant Would be great to get your eyeballs on this, too.

@tgrant-nv
Copy link
Contributor

Taking a look now.

@@ -411,7 +411,8 @@ class OSLEXECPUBLIC RendererServices {
virtual uint64_t register_string (const std::string& str,
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like register_string is vestigial now. Does it make sense to remove it? Or maybe there is some potential use beyond a fancy wrapper for ustring::hash?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would be in favor of removing it if not used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think you're right, but I wasn't sure about the compatibility break that would be incurred to removing a virtual method from the parent class. Maybe I'll just mark it as deprecated first?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is only for the next release, so I don't think this is too critical.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

YOLO, removed it entirely.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure you would have noticed, but if not it looks like there are a couple lingering uses of the function in the test programs that need a little bit of refactoring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, yeah, fixing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated. Builds fine now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Other than this, did the overall simplification look sane to you, @tgrant-nv ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, definitely. It's a huge improvement in readability and maintainability for GPU strings. I don't think anyone will miss trying to reason about load_device_string.

@cmstein
Copy link
Collaborator

cmstein commented Jul 11, 2022 via email

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz
Copy link
Collaborator Author

lgritz commented Jul 12, 2022

Will merge this at the end of the day. Register any final objections now.

@lgritz lgritz merged commit 7b4c7cf into AcademySoftwareFoundation:main Jul 13, 2022
@lgritz lgritz deleted the lg-stringoverhaul branch July 21, 2022 15:19
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.

None yet

4 participants