File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -371,22 +371,38 @@ class ET_EXPERIMENTAL CudaBackend final
371371
372372namespace executorch ::backends {
373373namespace {
374+ // Static backend instance and registration
374375auto cls = cuda::CudaBackend();
375376executorch::runtime::Backend backend{" CudaBackend" , &cls};
377+
378+ #ifndef _WIN32
379+ // On non-Windows platforms, use static initialization
376380static executorch::runtime::Error success_with_compiler =
377381 register_backend (backend);
382+ #endif
383+
378384} // namespace
379385
380- // Export an initialization function to ensure static initializers run on Windows
386+ // Export an initialization function for explicit backend registration
381387#ifdef _WIN32
382388#define CUDA_BACKEND_INIT_EXPORT __declspec (dllexport)
383389#else
384390#define CUDA_BACKEND_INIT_EXPORT __attribute__ ((visibility(" default" )))
385391#endif
386392
387393extern " C" CUDA_BACKEND_INIT_EXPORT void InitCudaBackend () {
388- // Force the static initializer to run by referencing it
394+ #ifdef _WIN32
395+ // On Windows, explicitly register the backend since DLL static initializers
396+ // don't run reliably
397+ static bool initialized = false ;
398+ if (!initialized) {
399+ register_backend (backend);
400+ initialized = true ;
401+ }
402+ #else
403+ // On other platforms, static initialization already happened
389404 (void )success_with_compiler;
405+ #endif
390406}
391407
392408} // namespace executorch::backends
You can’t perform that action at this time.
0 commit comments