1919#include  < string> 
2020#include  < vector> 
2121
22- //  Include our shim layer headers
22+ //  Include class header and shim layer headers
23+ #include  < executorch/backends/cuda/runtime/CudaBackend.h> 
2324#include  < executorch/backends/aoti/aoti_delegate_handle.h> 
2425#include  < executorch/backends/aoti/common_shims.h> 
25- #include  < executorch/backends/cuda/runtime/cuda_backend_init.h> 
2626#include  < executorch/backends/cuda/runtime/platform/platform.h> 
2727#include  < executorch/backends/cuda/runtime/shims/memory.h> 
2828#include  < executorch/backends/cuda/runtime/utils.h> 
@@ -48,12 +48,9 @@ using executorch::runtime::Result;
4848using  executorch::runtime::Span;
4949using  executorch::runtime::etensor::Tensor;
5050
51- class  ET_EXPERIMENTAL  CudaBackend final 
52-     : public ::executorch::runtime::BackendInterface {
53-  private: 
54-   Error load_function_pointers_into_handle (
55-       void * so_handle,
56-       AOTIDelegateHandle* handle) const  {
51+ Error CudaBackend::load_function_pointers_into_handle (
52+     void * so_handle,
53+     AOTIDelegateHandle* handle) const  {
5754#define  LOAD_SYMBOL (member, name )                                    \
5855  do  {                                                               \
5956    auto  symbol_res = get_function (so_handle, #name);                \
@@ -88,17 +85,14 @@ class ET_EXPERIMENTAL CudaBackend final
8885    return  Error::Ok;
8986  }
9087
91-  public: 
92-   bool  is_available () const  override  {
93-     return  1 ;
94-   }
88+ bool  CudaBackend::is_available () const  {
89+   return  1 ;
90+ }
9591
96-   //  Once per loaded binary blob
97-   Result<DelegateHandle*> init (
92+ Result<DelegateHandle*> CudaBackend::init (
9893      BackendInitContext& context,
99-       FreeableBuffer* processed, //  This will be a empty buffer
100-       ArrayRef<CompileSpec> compile_specs //  This will be my empty list
101-   ) const  override  {
94+       FreeableBuffer* processed,
95+       ArrayRef<CompileSpec> compile_specs) const  {
10296    std::string method_name;
10397    for  (const  CompileSpec& spec : compile_specs) {
10498      if  (std::strcmp (spec.key , " method_name" 0 ) {
@@ -196,11 +190,10 @@ class ET_EXPERIMENTAL CudaBackend final
196190    return  (DelegateHandle*)handle; //  Return the handle post-processing
197191  }
198192
199-   //  Once per execution
200-   Error execute (
201-       BackendExecutionContext& context,
202-       DelegateHandle* handle_,
203-       Span<EValue*> args) const  override  {
193+ Error CudaBackend::execute (
194+     BackendExecutionContext& context,
195+     DelegateHandle* handle_,
196+     Span<EValue*> args) const  {
204197    AOTIDelegateHandle* handle = (AOTIDelegateHandle*)handle_;
205198
206199    size_t  n_inputs;
@@ -322,7 +315,7 @@ class ET_EXPERIMENTAL CudaBackend final
322315    return  Error::Ok;
323316  }
324317
325-    void  destroy (DelegateHandle* handle_) const   override  {
318+ void  CudaBackend:: destroyconst  {
326319    if  (handle_ == nullptr ) {
327320      return ;
328321    }
@@ -367,54 +360,21 @@ class ET_EXPERIMENTAL CudaBackend final
367360    delete  handle;
368361    clear_all_tensors ();
369362  }
370- };
371363
372364} //  namespace executorch::backends::cuda
373365
374366namespace  executorch ::backends {
375- namespace  { 
376- //  Static backend  instance and registration 
367+ 
368+ //  Backend  instance - static on all platforms 
377369auto  cls = cuda::CudaBackend();
378- executorch::runtime::Backend backend {" CudaBackend" 
370+ executorch::runtime::Backend cuda_backend {" CudaBackend" 
379371
380372#ifndef  _WIN32
381- //  On non-Windows platforms, use static initialization
373+ //  On non-Windows platforms, use automatic static initialization
374+ namespace  {
382375static  executorch::runtime::Error success_with_compiler =
383-     register_backend (backend);
384- #endif 
385- 
376+     register_backend (cuda_backend);
386377} //  namespace
387- 
388- //  InitCudaBackend is exported for explicit backend registration on Windows
389- extern  " C" void  InitCudaBackend () {
390-   //  Log immediately to confirm function is entered
391-   ET_LOG (Info, " InitCudaBackend: Function entered" 
392-   assert (1 ==2 );
393-   
394- #ifdef  _WIN32
395-   ET_LOG (Info, " InitCudaBackend: Windows path" 
396-   //  On Windows, explicitly register the backend since DLL static initializers
397-   //  don't run reliably
398-   static  bool  initialized = false ;
399-   if  (!initialized) {
400-     ET_LOG (Info, " Registering CUDA backend on Windows" 
401-     auto  error = register_backend (backend);
402-     if  (error == executorch::runtime::Error::Ok) {
403-       ET_LOG (Info, " Successfully registered CudaBackend" 
404-     } else  {
405-       ET_LOG (Error, " Failed to register CudaBackend: error code %d" int )error);
406-     }
407-     initialized = true ;
408-   } else  {
409-     ET_LOG (Info, " CUDA backend already initialized" 
410-   }
411- #else 
412-   ET_LOG (Info, " InitCudaBackend: Non-Windows path" 
413-   //  On other platforms, static initialization already happened
414-   (void )success_with_compiler;
415378#endif 
416-   
417-   ET_LOG (Info, " InitCudaBackend: Function exiting" 
418- }
419379
420380} //  namespace executorch::backends
0 commit comments