mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-20 19:12:24 +00:00
Add cuda context headers to zip (#18330)
Expose cuda context headers for cuda custom ops. --------- Co-authored-by: Randy Shuai <rashuai@microsoft.com>
This commit is contained in:
parent
1ff894898a
commit
59262dfc63
4 changed files with 27 additions and 4 deletions
|
|
@ -1,5 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// This header is to expose a context for cuda custom ops.
|
||||
// By the context, a custom cuda operator could fetch existing resources,
|
||||
// such as cuda stream and cudnn handle, for reusing.
|
||||
|
||||
// For concrete usage, pls find page here:
|
||||
// https://onnxruntime.ai/docs/reference/operators/add-custom-op.html#custom-ops-for-cuda-and-rocm
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ORT_CUDA_CTX
|
||||
|
|
@ -21,7 +29,7 @@ struct CudaContext : public CustomOpContext {
|
|||
cublasHandle_t cublas_handle = {};
|
||||
OrtAllocator* deferred_cpu_allocator = {};
|
||||
|
||||
void Init(const OrtKernelContext& kernel_ctx) override {
|
||||
void Init(const OrtKernelContext& kernel_ctx) {
|
||||
const auto& ort_api = Ort::GetApi();
|
||||
void* resource = {};
|
||||
OrtStatus* status = nullptr;
|
||||
|
|
|
|||
|
|
@ -3,11 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <core/session/onnxruntime_cxx_api.h>
|
||||
|
||||
// CustomOpContext defines an interface allowing a custom op to access ep-specific resources.
|
||||
struct CustomOpContext {
|
||||
CustomOpContext() = default;
|
||||
virtual ~CustomOpContext(){};
|
||||
virtual void Init(const OrtKernelContext&){};
|
||||
};
|
||||
|
|
@ -39,6 +39,15 @@ steps:
|
|||
mkdir $(Build.BinariesDirectory)\${{parameters.artifactName}}\lib
|
||||
mkdir $(Build.BinariesDirectory)\${{parameters.artifactName}}\include
|
||||
|
||||
if exist $(Build.BinariesDirectory)\${{parameters.buildConfig}}\${{parameters.buildConfig}}\onnxruntime_providers_cuda.dll (
|
||||
echo "cuda context headers copied"
|
||||
mkdir $(Build.BinariesDirectory)\${{parameters.artifactName}}\include\core\providers\cuda
|
||||
copy $(Build.SourcesDirectory)\include\onnxruntime\core\providers\resource.h $(Build.BinariesDirectory)\${{parameters.artifactName}}\include\core\providers
|
||||
copy $(Build.SourcesDirectory)\include\onnxruntime\core\providers\custom_op_context.h $(Build.BinariesDirectory)\${{parameters.artifactName}}\include\core\providers
|
||||
copy $(Build.SourcesDirectory)\include\onnxruntime\core\providers\cuda\cuda_context.h $(Build.BinariesDirectory)\${{parameters.artifactName}}\include\core\providers\cuda
|
||||
copy $(Build.SourcesDirectory)\include\onnxruntime\core\providers\cuda\cuda_resource.h $(Build.BinariesDirectory)\${{parameters.artifactName}}\include\core\providers\cuda
|
||||
)
|
||||
|
||||
echo "Directories created"
|
||||
copy $(Build.BinariesDirectory)\${{parameters.buildConfig}}\${{parameters.buildConfig}}\onnxruntime.dll $(Build.BinariesDirectory)\${{parameters.artifactName}}\lib
|
||||
copy $(Build.BinariesDirectory)\${{parameters.buildConfig}}\${{parameters.buildConfig}}\onnxruntime_providers_shared.dll $(Build.BinariesDirectory)\${{parameters.artifactName}}\lib
|
||||
|
|
|
|||
|
|
@ -56,6 +56,15 @@ cp $SOURCE_DIR/orttraining/orttraining/training_api/include/onnxruntime_training
|
|||
cp $SOURCE_DIR/orttraining/orttraining/training_api/include/onnxruntime_training_cxx_api.h $BINARY_DIR/$ARTIFACT_NAME/include
|
||||
cp $SOURCE_DIR/orttraining/orttraining/training_api/include/onnxruntime_training_cxx_inline.h $BINARY_DIR/$ARTIFACT_NAME/include
|
||||
|
||||
if [[ -f "$BINARY_DIR/$BUILD_CONFIG/libonnxruntime_providers_cuda.so" ]]; then
|
||||
# copy headers for context context used in custom ops
|
||||
mkdir -p $BINARY_DIR/$ARTIFACT_NAME/include/core/providers/cuda
|
||||
cp $SOURCE_DIR/include/onnxruntime/core/providers/custom_op_context.h $BINARY_DIR/$ARTIFACT_NAME/include/core/providers/custom_op_context.h
|
||||
cp $SOURCE_DIR/include/onnxruntime/core/providers/resource.h $BINARY_DIR/$ARTIFACT_NAME/include/core/providers/resource.h
|
||||
cp $SOURCE_DIR/include/onnxruntime/core/providers/cuda/cuda_context.h $BINARY_DIR/$ARTIFACT_NAME/include/core/providers/cuda/cuda_context.h
|
||||
cp $SOURCE_DIR/include/onnxruntime/core/providers/cuda/cuda_resource.h $BINARY_DIR/$ARTIFACT_NAME/include/core/providers/cuda/cuda_resource.h
|
||||
fi
|
||||
|
||||
# copy the README, licence and TPN
|
||||
cp $SOURCE_DIR/README.md $BINARY_DIR/$ARTIFACT_NAME/README.md
|
||||
cp $SOURCE_DIR/docs/Privacy.md $BINARY_DIR/$ARTIFACT_NAME/Privacy.md
|
||||
|
|
|
|||
Loading…
Reference in a new issue