File tree Expand file tree Collapse file tree 4 files changed +46
-16
lines changed Expand file tree Collapse file tree 4 files changed +46
-16
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,11 @@ set(_aoti_cuda_sources
4747# Build as SHARED library (.dll) on Windows MSVC, otherwise STATIC
4848if (MSVC )
4949 add_library (aoti_cuda SHARED ${_aoti_cuda_sources} )
50- # Define export macro for Windows DLL
51- target_compile_definitions (aoti_cuda PRIVATE EXPORT_AOTI_FUNCTIONS)
50+ # Define export macros for Windows DLL
51+ target_compile_definitions (aoti_cuda PRIVATE
52+ EXPORT_AOTI_FUNCTIONS
53+ BUILDING_CUDA_BACKEND
54+ )
5255 # Ensure proper DLL import/export library naming on Windows with config-specific paths
5356 set_target_properties (aoti_cuda PROPERTIES
5457 WINDOWS_EXPORT_ALL_SYMBOLS OFF # We use explicit exports via AOTI_CUDA_EXPORT
Original file line number Diff line number Diff line change 2121// Include our shim layer headers
2222#include < executorch/backends/aoti/aoti_delegate_handle.h>
2323#include < executorch/backends/aoti/common_shims.h>
24+ #include < executorch/backends/cuda/runtime/cuda_backend_init.h>
2425#include < executorch/backends/cuda/runtime/platform/platform.h>
2526#include < executorch/backends/cuda/runtime/shims/memory.h>
2627#include < executorch/backends/cuda/runtime/utils.h>
@@ -383,14 +384,8 @@ static executorch::runtime::Error success_with_compiler =
383384
384385} // namespace
385386
386- // Export an initialization function for explicit backend registration
387- #ifdef _WIN32
388- #define CUDA_BACKEND_INIT_EXPORT __declspec (dllexport)
389- #else
390- #define CUDA_BACKEND_INIT_EXPORT __attribute__ ((visibility(" default" )))
391- #endif
392-
393- extern " C" CUDA_BACKEND_INIT_EXPORT void InitCudaBackend () {
387+ // InitCudaBackend is exported for explicit backend registration on Windows
388+ extern " C" CUDA_BACKEND_INIT_API void InitCudaBackend () {
394389 // Log immediately to confirm function is entered
395390 ET_LOG (Info, " InitCudaBackend: Function entered" );
396391
Original file line number Diff line number Diff line change 1+ // (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+ #pragma once
4+
5+ #ifdef __cplusplus
6+ extern "C" {
7+ #endif
8+
9+ #ifdef _WIN32
10+ #define CUDA_BACKEND_INIT_EXPORT __declspec(dllexport)
11+ #define CUDA_BACKEND_INIT_IMPORT __declspec(dllimport)
12+ #else
13+ #define CUDA_BACKEND_INIT_EXPORT __attribute__((visibility("default")))
14+ #define CUDA_BACKEND_INIT_IMPORT
15+ #endif
16+
17+ // When building the DLL, define BUILDING_CUDA_BACKEND
18+ // When using the DLL, this will import the function
19+ #ifdef BUILDING_CUDA_BACKEND
20+ #define CUDA_BACKEND_INIT_API CUDA_BACKEND_INIT_EXPORT
21+ #else
22+ #define CUDA_BACKEND_INIT_API CUDA_BACKEND_INIT_IMPORT
23+ #endif
24+
25+ /**
26+ * Initialize the CUDA backend and register it with the ExecutorTorch runtime.
27+ * On Windows, this must be called explicitly before loading models that use
28+ * the CUDA backend. On other platforms, the backend is registered automatically
29+ * via static initialization.
30+ */
31+ CUDA_BACKEND_INIT_API void InitCudaBackend ();
32+
33+ #ifdef __cplusplus
34+ }
35+ #endif
Original file line number Diff line number Diff line change @@ -282,15 +282,12 @@ MultimodalInput processAudioFile(
282282
283283} // namespace
284284
285- // Forward declare the initialization function from aoti_cuda
286- #ifdef _WIN32
287- extern " C" __declspec(dllimport) void InitCudaBackend ();
288- #else
289- extern " C" void InitCudaBackend ();
285+ #ifdef EXECUTORCH_BUILD_CUDA
286+ #include < executorch/backends/cuda/runtime/cuda_backend_init.h>
290287#endif
291288
292289int32_t main (int32_t argc, char ** argv) {
293- #ifdef _WIN32
290+ #ifdef EXECUTORCH_BUILD_CUDA
294291 // On Windows, explicitly initialize the CUDA backend to ensure
295292 // static initializers in the DLL run
296293 ET_LOG (Info, " About to call InitCudaBackend" );
You can’t perform that action at this time.
0 commit comments