Skip to content

Commit 94dd1f6

Browse files
Eashan Gargfacebook-github-bot
authored andcommitted
Unique .so paths to support multiple CUDA delegates
Summary: Some export flows need to generate multiple .so files (for ex/, exporting audio encoder and speech decoder of gemma3n as separate .ptes with their own blobs) Differential Revision: D101883539
1 parent 0919746 commit 94dd1f6

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

backends/cuda/runtime/cuda_backend.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cstdio>
1818

1919
#include <array>
20+
#include <atomic>
2021
#include <filesystem>
2122
#include <fstream>
2223
#include <mutex>
@@ -314,10 +315,14 @@ class ET_EXPERIMENTAL CudaBackend final
314315
so_blob_key.c_str(),
315316
static_cast<uint32_t>(aoti_dso_buffer.error()));
316317

317-
// Generate dynamic temporary file path
318+
// Generate dynamic temporary file path with unique counter to support
319+
// multiple CUDA delegates in the same process. Atomic to avoid races
320+
// when multiple delegates are loaded concurrently.
321+
static std::atomic<int> delegate_counter{0};
322+
int delegate_id = delegate_counter.fetch_add(1, std::memory_order_relaxed);
318323
filesystem::path temp_dir = filesystem::temp_directory_path();
319324
filesystem::path so_path =
320-
temp_dir / (so_blob_key + to_string(get_process_id()) + ".so");
325+
temp_dir / (so_blob_key + to_string(get_process_id()) + "_" + to_string(delegate_id) + ".so");
321326

322327
// Create a temporary file
323328
ofstream outfile(so_path, ios::binary);

0 commit comments

Comments
 (0)