Skip to content

Commit efcdfa1

Browse files
committed
hacky work to get backend registration
1 parent 0bbcd71 commit efcdfa1

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

backends/cuda/runtime/cuda_backend.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,17 @@ executorch::runtime::Backend backend{"CudaBackend", &cls};
376376
static executorch::runtime::Error success_with_compiler =
377377
register_backend(backend);
378378
} // namespace
379+
380+
// Export an initialization function to ensure static initializers run on Windows
381+
#ifdef _WIN32
382+
#define CUDA_BACKEND_INIT_EXPORT __declspec(dllexport)
383+
#else
384+
#define CUDA_BACKEND_INIT_EXPORT __attribute__((visibility("default")))
385+
#endif
386+
387+
extern "C" CUDA_BACKEND_INIT_EXPORT void InitCudaBackend() {
388+
// Force the static initializer to run by referencing it
389+
(void)success_with_compiler;
390+
}
391+
379392
} // namespace executorch::backends

examples/models/voxtral/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,6 @@ list(
8484
extension_flat_tensor
8585
)
8686

87-
# Link CUDA backend
88-
if(EXECUTORCH_BUILD_CUDA)
89-
find_package(CUDAToolkit REQUIRED)
90-
list(APPEND link_libraries aoti_cuda)
91-
# CMake will automatically use the import library on Windows
92-
if(NOT MSVC)
93-
# Only apply shared lib linking options on non-Windows platforms
94-
executorch_target_link_options_shared_lib(aoti_cuda)
95-
endif()
96-
endif()
97-
9887
if(EXECUTORCH_BUILD_METAL)
9988
list(APPEND link_libraries metal_backend)
10089
executorch_target_link_options_shared_lib(metal_backend)
@@ -111,6 +100,17 @@ if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
111100
endif()
112101
endif()
113102

103+
# Link CUDA backend
104+
if(EXECUTORCH_BUILD_CUDA AND NOT MSVC)
105+
find_package(CUDAToolkit REQUIRED)
106+
list(APPEND link_libraries aoti_cuda)
107+
executorch_target_link_options_shared_lib(aoti_cuda)
108+
elseif(EXECUTORCH_BUILD_CUDA AND MSVC)
109+
find_package(CUDAToolkit REQUIRED)
110+
target_link_libraries(voxtral_runner PRIVATE aoti_cuda)
111+
executorch_target_link_options_shared_lib(aoti_cuda)
112+
endif()
113+
114114
target_include_directories(voxtral_runner PUBLIC ${_common_include_directories})
115115
target_link_libraries(voxtral_runner PUBLIC ${link_libraries})
116116
target_compile_options(voxtral_runner PUBLIC ${_common_compile_options})

examples/models/voxtral/multimodal.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,16 @@ MultimodalInput processAudioFile(
282282

283283
} // namespace
284284

285+
// Forward declare the initialization function from aoti_cuda
286+
extern "C" void InitCudaBackend();
287+
285288
int32_t main(int32_t argc, char** argv) {
289+
#ifdef _WIN32
290+
// On Windows, explicitly initialize the CUDA backend to ensure
291+
// static initializers in the DLL run
292+
InitCudaBackend();
293+
#endif
294+
286295
gflags::ParseCommandLineFlags(&argc, &argv, true);
287296

288297
const char* model_path = FLAGS_model_path.c_str();

0 commit comments

Comments
 (0)