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

[js/node] allow arenaExtendStrategy and gpuMemLimit option for CUDA EP #23176

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: 9 additions & 0 deletions js/common/lib/inference-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ export declare namespace InferenceSession {
export interface CudaExecutionProviderOption extends ExecutionProviderOption {
readonly name: 'cuda';
deviceId?: number;
gpuMemLimit?: number;

/**
* Arena extend strategy. See
* https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/framework/arena_extend_strategy.h
*
* This setting is available only in ONNXRuntime (Node.js binding)
*/
arenaExtendStrategy?: 0 | 1;
}
export interface DmlExecutionProviderOption extends ExecutionProviderOption {
readonly name: 'dml';
Expand Down
16 changes: 16 additions & 0 deletions js/node/src/session_options_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
Napi::Value epValue = epList[i];
std::string name;
int deviceId = 0;
#ifdef USE_CUDA
onnxruntime::ArenaExtendStrategy arenaExtendStrategy = onnxruntime::ArenaExtendStrategy::kNextPowerOfTwo;
size_t gpuMemLimit = std::numeric_limits<size_t>::max();

Check warning on line 46 in js/node/src/session_options_helper.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <limits> for numeric_limits<> [build/include_what_you_use] [4] Raw Output: js/node/src/session_options_helper.cc:46: Add #include <limits> for numeric_limits<> [build/include_what_you_use] [4]
#endif
#ifdef USE_COREML
int coreMlFlags = 0;
#endif
Expand All @@ -59,6 +63,16 @@
if (obj.Has("deviceId")) {
deviceId = obj.Get("deviceId").As<Napi::Number>();
}
#ifdef USE_CUDA
if (obj.Has("arenaExtendStrategy")) {
arenaExtendStrategy = static_cast<onnxruntime::ArenaExtendStrategy>(
obj.Get("arenaExtendStrategy").As<Napi::Number>().Uint32Value());
}
if (obj.Has("gpuMemLimit")) {
gpuMemLimit = static_cast<size_t>(
obj.Get("gpuMemLimit").As<Napi::Number>().DoubleValue());
}
#endif
#ifdef USE_COREML
if (obj.Has("coreMlFlags")) {
coreMlFlags = obj.Get("coreMlFlags").As<Napi::Number>();
Expand Down Expand Up @@ -86,6 +100,8 @@
OrtCUDAProviderOptionsV2* options;
Ort::GetApi().CreateCUDAProviderOptions(&options);
options->device_id = deviceId;
options->arena_extend_strategy = arenaExtendStrategy;
options->gpu_mem_limit = gpuMemLimit;
sessionOptions.AppendExecutionProvider_CUDA_V2(*options);
Ort::GetApi().ReleaseCUDAProviderOptions(options);
#endif
Expand Down
Loading