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

[CUDA] Acquiring a CUDA allocator without loading a session. #19420

Open
gedoensmax opened this issue Feb 5, 2024 · 2 comments
Open

[CUDA] Acquiring a CUDA allocator without loading a session. #19420

gedoensmax opened this issue Feb 5, 2024 · 2 comments
Labels
ep:CUDA issues related to the CUDA execution provider

Comments

@gedoensmax
Copy link
Contributor

Describe the issue

I am aware that I can create and register an allocator to the active environment so that my session does not create it's own allocator, but rather uses the already attached allocator.

static auto ort_env = Ort::Env(ORT_LOGGING_LEVEL_WARNING);

static auto ort_api = Ort::GetApi();

const Ort::ArenaCfg arena_cfg(0, -1, -1, -1);

std::vector<const char *> dummy;

ort_api.CreateAndRegisterAllocatorV2(ort_env, "cuda", memory_info_cuda, arena_cfg, dummy.data(), dummy.data(), 0);


After registering with the above code I should be able to reuse this allocator with multiple sessions (Note: How would I go about doing this with C++ API ? I am not able to find any docs on this)
My problem is I would like to use this allocator to allocate tensors before loading an ONNX file. As far as I can tell there is no option to do this right ?

To reproduce

Usage of the C++ API.

Urgency

No response

Platform

Windows

OS Version

Winows and Linux

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1.17

ONNX Runtime API

C++

Architecture

X64

Execution Provider

Default CPU, CUDA, TensorRT

Execution Provider Library Version

No response

@tianleiwu
Copy link
Contributor

tianleiwu commented Feb 5, 2024

There is no explicit API to get cuda allocator from Env. Current allocator API is associated with session.

You can take a look at OrtValue or Ort::Value, which need not associate with session, and it can be used to create tensor. Then you can bind the tensors with inputs/outputs of one or mutliple sessions.

https://onnxruntime.ai/docs/api/c/struct_ort_1_1_value.html
image

@sophies927 sophies927 added the ep:CUDA issues related to the CUDA execution provider label Feb 22, 2024
@gedoensmax
Copy link
Contributor Author

@tianleiwu this would require usage of specific backend APIs which ORT tries to mitigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:CUDA issues related to the CUDA execution provider
Projects
None yet
Development

No branches or pull requests

3 participants