Skip to content

OnnxRuntime C# bindings and multi gpu memory allocation. #24453

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

Open
BernhardGlueck opened this issue Apr 17, 2025 · 1 comment
Open

OnnxRuntime C# bindings and multi gpu memory allocation. #24453

BernhardGlueck opened this issue Apr 17, 2025 · 1 comment
Labels
api:CSharp issues related to the C# API

Comments

@BernhardGlueck
Copy link

BernhardGlueck commented Apr 17, 2025

Describe the issue

System: 2x RTX 4090, fully working ( pytorch, etc )

I am trying to implement multi gpu inference ( by splitting my inputs up etc )
When i create my memory allocator for Ort Tensors like this:

 var memoryInfo = new OrtMemoryInfo(OrtMemoryInfo.allocatorCUDA_PINNED,
               OrtAllocatorType.DeviceAllocator,
                deviceId,
                OrtMemType.CpuInput | OrtMemType.CpuOutput);

  var ortAllocator = new OrtAllocator(session, memoryInfo);

The session was of course created on the correct device as well:

  var cudaOptions = new OrtCUDAProviderOptions()
        {
        };

        cudaOptions.UpdateOptions(new Dictionary<string, string>()
        {
            { "device_id", deviceId.ToString() },
            { "enable_cuda_graph", "1" },
            { "cudnn_conv_use_max_workspace", "1" }
        });

        sessionOptions.AppendExecutionProvider_CUDA(cudaOptions);

This works fine for my first card ( deviceId = 0 ) but for deviceId = 1 i get an error:
[ErrorCode:InvalidArgument] No requested allocator available

Could this be an issue or is there some incantantion to make this work ?

To reproduce

´´´
var memoryInfo = new OrtMemoryInfo(OrtMemoryInfo.allocatorCUDA_PINNED,
OrtAllocatorType.DeviceAllocator,
deviceId,
OrtMemType.CpuInput | OrtMemType.CpuOutput);

var ortAllocator = new OrtAllocator(session, memoryInfo);
´´´

Urgency

No response

Platform

Windows

OS Version

Fedora 41

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.21.0

ONNX Runtime API

C#

Architecture

X64

Execution Provider

CUDA

Execution Provider Library Version

Cuda 12.8

@github-actions github-actions bot added the api:CSharp issues related to the C# API label Apr 17, 2025
@yuslepukhin
Copy link
Member

We do not support multiple devices, and the second device allocator is simply not instantiated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:CSharp issues related to the C# API
Projects
None yet
Development

No branches or pull requests

2 participants