Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions backends/cuda/runtime/cuda_backend.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
Expand All @@ -17,6 +17,7 @@
#include <cstdio>

#include <array>
#include <atomic>
#include <filesystem>
#include <fstream>
#include <mutex>
Expand Down Expand Up @@ -314,10 +315,14 @@
so_blob_key.c_str(),
static_cast<uint32_t>(aoti_dso_buffer.error()));

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

// Create a temporary file
ofstream outfile(so_path, ios::binary);
Expand Down
Loading