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

Segmentation fault while trying to use AppendExecutionProvider_CUDA #23492

Closed
UnlimitedR opened this issue Jan 25, 2025 · 2 comments
Closed

Segmentation fault while trying to use AppendExecutionProvider_CUDA #23492

UnlimitedR opened this issue Jan 25, 2025 · 2 comments

Comments

@UnlimitedR
Copy link

UnlimitedR commented Jan 25, 2025

Describe the issue

my current codes is like this

        std::vector<std::string> availableProviders = Ort::GetAvailableProviders();
        auto cudaAvailable = std::find(availableProviders.begin(), availableProviders.end(), "CUDAExecutionProvider");
        std::cout << availableProviders << std::endl;
        OrtCUDAProviderOptions cudaOption;
        if (cudaAvailable != availableProviders.end()) {
            session_options_.AppendExecutionProvider_CUDA(cudaOption);
        }

while session_options_ is a private member of the class I created Ort::SessionOptions session_options_{ nullptr };

I'm debugging this in VS code and these are the codes before the crash happens

template <typename T>
inline SessionOptionsImpl<T>& SessionOptionsImpl<T>::AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options) {
  ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_CUDA(this->p_, &provider_options));
  return *this;
}

in onnxruntime-linux-x64-gpu-1.20.1/include/onnxruntime_cxx_inline.h

and then

/// This returns a reference to the OrtApi interface in use
inline const OrtApi& GetApi() noexcept { return *Global<void>::api_; }

in onnxruntime-linux-x64-gpu-1.20.1/include/onnxruntime_cxx_inline.h

and then

Exception has occurred.
Segmentation fault

happens

I'm using WSL and I'm pretty sure the correct versions of CUDA and CUDNN are installed (CUDA 12.6 and CUDNN 9)

To reproduce

minimal files to reproduce the issue
the testonnx.cpp file

#include <onnxruntime_cxx_api.h>
#include <iostream>
#include <string>
#include <vector>

class ONNXModel {
public:
    ONNXModel() 
    {
        env_ = Ort::Env(OrtLoggingLevel::ORT_LOGGING_LEVEL_WARNING, "test");

        std::vector<std::string> availableProviders = Ort::GetAvailableProviders();
        auto cudaAvailable = std::find(availableProviders.begin(), availableProviders.end(), "CUDAExecutionProvider");
        // std::cout << availableProviders << std::endl;
        OrtCUDAProviderOptions cudaOption;
        if (cudaAvailable != availableProviders.end()) {
            session_options_.AppendExecutionProvider_CUDA(cudaOption);
        }
    }
private:
	Ort::Env env_{ nullptr };
	Ort::SessionOptions session_options_{ nullptr };
};

int main(int argc, char** argv) {

    ONNXModel model;
    return 0;
}

and the CMakeLists.txt file

cmake_minimum_required(VERSION 3.10)

# Set your project name
project(test)

# Specify the path to ONNX Runtime headers and libraries
set(CMAKE_PREFIX_PATH "~/Downloads/onnxruntime-linux-x64-gpu-1.20.1/lib64/cmake/onnxruntime")
find_package(onnxruntime REQUIRED)
# Add your executable or library
add_executable(test testonnx.cpp)
target_link_libraries(test PRIVATE onnxruntime::onnxruntime)

set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

Urgency

No response

Platform

Linux

OS Version

Ubuntu 24.04

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

onnxruntime-linux-x64-gpu-1.20.1

ONNX Runtime API

C++

Architecture

X64

Execution Provider

CUDA

Execution Provider Library Version

CUDA 12.6

@UnlimitedR
Copy link
Author

the CPU inference is correct on my machine, but as long as I add the line session_options_.AppendExecutionProvider_CUDA(cudaOption);, the segmentation error will happen.
`

@UnlimitedR
Copy link
Author

that's funny if I the change the line to Ort::SessionOptions session_options_ = Ort::SessionOptions(); the error disappears.
I think it is really lacking tutorials and I just reference codes from online sources, and many of them are buggy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant