AcademySoftwareFoundation / AcademySoftwareFoundation/OpenShadingLanguage

Optimize_group not thread safe when generating PTX for GPU runtime.

Open
#1,181 19 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.3k
Forks
414
Avg merge
3d 1h
Merged PRs (30d)
10

Description

### Problem

We're trying to parallelize the PTX compilation of our OSL shaders as this generation time is becoming a bottleneck. In our current prototype we build the group in serial for all the shaders and then just run `ShadingSystem::optimize_group` on the groups in parallel to generate the PTX. All the callbacks to code on our end that could be called during this have been made thread safe. It seems that calling `ShadingSystem::optimize_group` in parallel produces bad PTX that OptiX will reject. Here is the output from OptiX,

```
Parse error (Details: Function "_rtProgramCreateFromPTXString" caught exception: (api input string): error: Failed to parse input PTX string
(api input string), line 26694; error : Unknown symbol 'prototype_708'
(api input string), line 26694; error : Arguments mismatch for instruction 'call'
(api input string), line 26699; error : Unknown symbol 'prototype_708'
(api input string), line 27288; error : Unknown symbol 'prototype_724'
(api input string), line 27288; error : Arguments mismatch for instruction 'call'
(api input string), line 27293; error : Unknown symbol 'prototype_724'
(api input string), line 34108; error : Unknown symbol 'prototype_1118'
(api input string), line 34108; error : Arguments mismatch for instruction 'call'
(api input string), line 34113; error : Unknown symbol 'prototype_1118'
Cannot parse input PTX string
)
```
Interestingly when compiling in serial all these "prototype" symbols are no longer present in the PTX produced. So I guess something in this API call isn't thread safe and the code is getting mashed up.

Improving this would be super helpful as currently we're forced to compile all the PTX in serial and as soon as you have say 10 shaders that take 6 seconds to compile you're now into the minutes before you have even started rendering. Happy to provide more information or generated PTX if needed.

### Versions

* OSL branch/version: master
* OS: windows / linux
* C++ compiler: clang 8.0.1 / 9.0.1
* LLVM version: 8.0.1 / 9.0.1

Contributor guide

Open the contributing guide

Research direction

Start with ShadingSystem::optimize_group and reproduce parallel PTX generation using the reported Windows or Linux configurations. Compare serial and parallel PTX output, then verify that concurrent calls produce valid PTX without the prototype symbols or OptiX parse errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.