Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new APIs for ORT-genai #725

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion include/custom_op/custom_op_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class OrtGraphCudaKernelContext : public CUDAKernelContext {
public:
static const int cuda_resource_ver = 1;

OrtGraphCudaKernelContext(const OrtApi& api, const OrtKernelContext& ctx) : api_(api) {
OrtGraphCudaKernelContext(const OrtApi& api, const OrtKernelContext& ctx) : api_(api), kernel_context_(ctx) {
api.KernelContext_GetResource(&ctx, cuda_resource_ver, CudaResource::cuda_handle_t, &cuda_stream_);
if (!cuda_stream_) {
ORTX_CXX_API_THROW("Failed to fetch cuda stream from context", ORT_RUNTIME_EXCEPTION);
Expand Down Expand Up @@ -526,8 +526,15 @@ class OrtGraphCudaKernelContext : public CUDAKernelContext {
return device_id_;
}

void* GetScratchBufferUnderMultiStream(const OrtMemoryInfo* mem_info, size_t count_or_bytes) override {
void* ret = nullptr;
api_.KernelContext_GetScratchBuffer(&kernel_context_, mem_info, count_or_bytes, &ret);
return ret;
}

private:
const OrtApi& api_;
const OrtKernelContext& kernel_context_;
OrtAllocator* cpu_allocator_;
OrtAllocator* cuda_allocator_;
void* cuda_stream_ = {};
Expand Down
2 changes: 2 additions & 0 deletions include/custom_op/kernel_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <optional>
#include <numeric>
#include <type_traits>
#include "onnxruntime_c_api.h"

namespace Ort {
namespace Custom {
Expand All @@ -29,6 +30,7 @@ class CUDAKernelContext : public KernelContext {
virtual void* GetCudaStream() const = 0;
virtual void* GetCublasHandle() const = 0;
virtual int GetCudaDeviceId() const = 0;
virtual void* GetScratchBufferUnderMultiStream(const OrtMemoryInfo* , size_t ) { return nullptr; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can you cannot use ORT type here since these classes will be used in eager mode which doesn't depend on ORT

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we need to decouple it from ORT types.

};
#endif

Expand Down
3 changes: 3 additions & 0 deletions include/ort_c_to_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class API {
return instance()->KernelContext_GetAllocator(context, mem_info, out);
}
#endif
static void ReleaseMemoryInfo(OrtMemoryInfo* mem_info) {
return instance()->ReleaseMemoryInfo(mem_info);
}
private:
const OrtApi* operator->() const {
return &api_;
Expand Down
Loading