microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
includes/kernel_context.h
34lines · modecode
| 1 | #pragma once |
| 2 | #include <optional> |
| 3 | #include <numeric> |
| 4 | #include <type_traits> |
| 5 | |
| 6 | namespace Ort { |
| 7 | namespace Custom { |
| 8 | |
| 9 | // this is for the ORT custom op template magic |
| 10 | class Arg { |
| 11 | }; |
| 12 | |
| 13 | class KernelContext : public Arg{ |
| 14 | public: |
| 15 | virtual void* AllocScratchBuffer(size_t size) = 0; |
| 16 | virtual void FreeScratchBuffer(void* p) = 0; |
| 17 | // TODO: threadpool? |
| 18 | }; |
| 19 | |
| 20 | #ifdef USE_CUDA |
| 21 | class CUDAKernelContext : public KernelContext { |
| 22 | public: |
| 23 | virtual void* AllocCudaScratchBuffer(size_t size) = 0; |
| 24 | virtual void FreeCudaScratchBuffer(void* p) = 0; |
| 25 | virtual void* GetCudaStream() const = 0; |
| 26 | virtual void* GetCublasHandle() const = 0; |
| 27 | virtual int GetCudaDeviceId() const = 0; |
| 28 | }; |
| 29 | #endif |
| 30 | |
| 31 | // TODO: helper func to create context from global ORT env. |
| 32 | |
| 33 | } |
| 34 | } |