tqchen commented on issue #265:
URL: https://github.com/apache/tvm-ffi/issues/265#issuecomment-3570696020

   OK, refining things further, i think we should be able to hide everything 
under ffi::Function, no changes to core/registry etc while still getting 
minimal overheads. We can iterate on API names and impl details, but to 
illsurtate the idea:
   
   ```c++
   
   // implemented in the following file
   #include <tvm/ffi/extra/function_overloading.h>
   
   // simple two function impl, we can use vargs template here
   template<typename FuncA, typename FuncB>
   class TypedOverloadedFunc {
     public:
      // exposes call packed signature
      void operator(const AnyView* args, int32_t num_args, Any* result){
         // dispatch into func_a and func_b here 
      }
   
     private:
       FuncA func_a_;
       FuncB func_b_;
   }
   
   template<typename FuncA, typename FuncB>
   ffi::Function CreateOverloadedFunction(FuncA fa, FuncB fb) {
       return ffi::Function::FromPacked(TypedOverloadedFunc<FuncA, FuncB>(fa, 
fb));
   }
   ```
   
   The implementation efficiency will be as efficient as the specialized impl 
because everything will be unlined into the packed function closure. User just 
need to be mindeful create overloaded function while from registry pov it is 
just ffi::Function
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to