microsoft/onnxruntime-extensions
Publicmirrored from https://github.com/microsoft/onnxruntime-extensionsAvailable
include/custom_op/kernel_context.h
38lines · modeblame
97ee9eb5Wenbing Li2 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. | |
| 3 | | |
64646279Wenbing Li2 years ago | 4 | #pragma once |
| 5 | #include <optional> | |
| 6 | #include <numeric> | |
| 7 | #include <type_traits> | |
| 8 | | |
| 9 | namespace Ort { | |
| 10 | namespace Custom { | |
| 11 | | |
| 12 | // this is for the ORT custom op template magic | |
| 13 | struct Arg { | |
| 14 | virtual ~Arg() = default; | |
| 15 | }; | |
| 16 | | |
| 17 | class KernelContext : public Arg{ | |
| 18 | public: | |
| 19 | virtual void* AllocScratchBuffer(size_t size) = 0; | |
| 20 | virtual void FreeScratchBuffer(void* p) = 0; | |
| 21 | // TODO: threadpool? | |
| 22 | }; | |
| 23 | | |
| 24 | #ifdef USE_CUDA | |
| 25 | class CUDAKernelContext : public KernelContext { | |
| 26 | public: | |
| 27 | virtual void* AllocCudaScratchBuffer(size_t size) = 0; | |
| 28 | virtual void FreeCudaScratchBuffer(void* p) = 0; | |
| 29 | virtual void* GetCudaStream() const = 0; | |
| 30 | virtual void* GetCublasHandle() const = 0; | |
| 31 | virtual int GetCudaDeviceId() const = 0; | |
| 32 | }; | |
| 33 | #endif | |
| 34 | | |
| 35 | // TODO: helper func to create context from global ORT env. | |
| 36 | | |
| 37 | } | |
| 38 | } |