microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
include/custom_op/kernel_context.h
35lines · 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 | struct Arg { |
| 11 | virtual ~Arg() = default; |
| 12 | }; |
| 13 | |
| 14 | class KernelContext : public Arg{ |
| 15 | public: |
| 16 | virtual void* AllocScratchBuffer(size_t size) = 0; |
| 17 | virtual void FreeScratchBuffer(void* p) = 0; |
| 18 | // TODO: threadpool? |
| 19 | }; |
| 20 | |
| 21 | #ifdef USE_CUDA |
| 22 | class CUDAKernelContext : public KernelContext { |
| 23 | public: |
| 24 | virtual void* AllocCudaScratchBuffer(size_t size) = 0; |
| 25 | virtual void FreeCudaScratchBuffer(void* p) = 0; |
| 26 | virtual void* GetCudaStream() const = 0; |
| 27 | virtual void* GetCublasHandle() const = 0; |
| 28 | virtual int GetCudaDeviceId() const = 0; |
| 29 | }; |
| 30 | #endif |
| 31 | |
| 32 | // TODO: helper func to create context from global ORT env. |
| 33 | |
| 34 | } |
| 35 | } |
| 36 | |