microsoft / microsoft/onnxruntime

Create session has different gpu memory (EP: CUDA)

Open
#9,138 9 comments 1 reaction 1 assignee View on GitHub

@hariharans29 is already working on this.

Since Sep 22, 2021.

core runtime ep:CUDA
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 8h
Merged PRs (30d)
179

Description

Describe the bugs:

Create session has different gpu memory (EP: CUDA)

System information:
  • Linux Ubuntu 20.04 (GCC 9.3)
  • ONNX Runtime installed build from source
  • ONNX Runtime version: 1.8.2
  • GPU model and memory: GeForce GTX 1060 MaxQ
Discussed in https://github.com/microsoft/onnxruntime/discussions/9137

Originally posted by mifikri September 21, 2021
Hi, i'm trying to create session below using c++ and configuring with cmake.
Model : yolov4.onnx

Dependencies:

  • Ort : 1.8.2
  • Torch: 1.9.0

CMakeLists.txt

cmake_minimum_required(VERSION 3.14)
project(main)

add_executable(${PROJECT_NAME} main.cpp)

target_include_directories(${PROJECT_NAME} 
    PRIVATE 
    /usr/local/include/onnxruntime
)

# find_package(Torch REQUIRED)

target_link_libraries(
    ${PROJECT_NAME}
    onnxruntime
    # ${TORCH_LIBRARIES}
)

main.cpp

#include <onnxruntime_cxx_api.h>
#include <onnxruntime/core/providers/cuda/cuda_provider_factory.h>
#include <unistd.h>
#include <iostream>

void initialize_session(std::string model_path, bool buffered){
    static Ort::Env env(ORT_LOGGING_LEVEL_INFO, "");    
    Ort::SessionOptions session_options;

    Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CUDA(session_options, 0));

    session_options.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_BASIC); 
    session_options.SetExecutionMode(ExecutionMode::ORT_SEQUENTIAL);
    if (buffered) {
        auto session = Ort::Session(env, model_path.c_str(), model_path.size(), session_options);
    }
    else {
        auto session = Ort::Session(env, model_path.c_str(), session_options);
    }
    std::cout<<"model loaded\n";
    
}

int main()
{
    std::string model_path = "/workspaces/vortex-runtime/data/yolov4.onnx";
    bool buffered = false;

    initialize_session(model_path, buffered);
    while(true)
    {
        sleep(1);
        std::cout<<"infer\n";
    }
}

Scenario: cmake configure with other linking libraries (torch)

GPU Memory:

model linking Ort 1.8.2 linking Ort 1.8.2 + Torch 1.9.0
yolov4.onnx 207 MiB 825 MiB

linking onnxruntime
Screenshot from 2021-09-21 14-39-20

The profiling test indicate that there is no memory dealocation (cuda free) while create session (linking onnxruntime+torch)

linking onnxruntime + torch
Screenshot from 2021-09-21 14-39-27

Have anyone ever met these kind of scenario / test ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.