-
Notifications
You must be signed in to change notification settings - Fork 0
OSL Cache v0 #2
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
base: main
Are you sure you want to change the base?
OSL Cache v0 #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -848,13 +848,35 @@ ShaderGroup::setup_interactive_arena(cspan<uint8_t> paramblock) | |
|
|
||
|
|
||
|
|
||
| std::string | ||
| ShaderGroup::generate_optix_cache_key() | ||
| { | ||
| const uint64_t ir_key = Strutil::strhash(serialize_internal()); | ||
|
|
||
| std::string safegroup; | ||
| safegroup = Strutil::replace(name(), "/", "_", true); | ||
| safegroup = Strutil::replace(safegroup, ":", "_", true); | ||
|
|
||
| std::string cache_key = fmtformat("cache-osl-{}-{}", safegroup, ir_key); | ||
|
|
||
| m_optix_cache_key = cache_key; | ||
| return m_optix_cache_key; | ||
| } | ||
|
|
||
| std::string | ||
| ShaderGroup::serialize() const | ||
| { | ||
| lock_guard lock(m_mutex); | ||
| return serialize_internal(); | ||
| } | ||
|
|
||
| std::string | ||
| ShaderGroup::serialize_internal() const | ||
| { | ||
| std::ostringstream out; | ||
| out.imbue(std::locale::classic()); // force C locale | ||
| out.precision(9); | ||
| lock_guard lock(m_mutex); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This lock caused me some trouble. ShadingSystemImpl::optimize_group grabs the same lock, and then calls serialize, so we deadlock without a change. This is a quick fix, a recursive mutex would be another. I don't understand the locking scheme well enough to know the right call here. |
||
|
|
||
| for (int i = 0, nl = nlayers(); i < nl; ++i) { | ||
| const ShaderInstance* inst = m_layers[i].get(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,12 @@ struct PerThreadInfo { | |
|
|
||
| namespace pvt { | ||
|
|
||
| void | ||
| optix_cache_unwrap(const std::string& cache_value, std::string& ptx, | ||
| size_t& groupdata_size); | ||
| std::string | ||
| optix_cache_wrap(const std::string& ptx, size_t groupdata_size); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't sure where to put these functions. They should be paired up, but one is used in llvm_instance and the other in shadingsys. |
||
|
|
||
| // forward definitions | ||
| class ShadingSystemImpl; | ||
| class ShaderInstance; | ||
|
|
@@ -1829,6 +1835,9 @@ class ShaderGroup { | |
| void name(ustring name) { m_name = name; } | ||
| ustring name() const { return m_name; } | ||
|
|
||
| std::string generate_optix_cache_key(); | ||
| std::string optix_cache_key() const { return m_optix_cache_key; } | ||
|
|
||
| std::string serialize() const; | ||
|
|
||
| void lock() const { m_mutex.lock(); } | ||
|
|
@@ -1965,6 +1974,8 @@ class ShaderGroup { | |
| } | ||
|
|
||
| private: | ||
| std::string serialize_internal() const; | ||
|
|
||
| // Put all the things that are read-only (after optimization) and | ||
| // needed on every shade execution at the front of the struct, as much | ||
| // together on one cache line as possible. | ||
|
|
@@ -2016,6 +2027,8 @@ class ShaderGroup { | |
| atomic_ll m_executions { 0 }; ///< Number of times the group executed | ||
| atomic_ll m_stat_total_shading_time_ticks { 0 }; // Shading time (ticks) | ||
|
|
||
| std::string m_optix_cache_key; | ||
|
|
||
| // PTX assembly for compiled ShaderGroup | ||
| std::string m_llvm_ptx_compiled_version; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The external cache API. Should the names include "optix" or be generic?