Git Product home page Git Product logo

Comments (5)

tianleiwu avatar tianleiwu commented on August 19, 2024 1

(1) Cuda graph requires inputs binded to a fixed buffer in GPU (so you will need copy input to the same address in GPU memory for every run). In your case, the input is binded to CPU:

Ort::MemoryInfo memory_info = Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU);

(2)
Memory is deleted before reading the data to a vector:

cudaFree(output_data_ptr); //suhail
...
std::vector output(rawOutput, rawOutput + count);

Please follow the following examples to use IO/Binding and CUDA Graph:

TEST(CApiTest, io_binding_cuda) {

TEST(CApiTest, basic_cuda_graph) {

from onnxruntime.

yuslepukhin avatar yuslepukhin commented on August 19, 2024

Where do you populate input/output names?

from onnxruntime.

suhailes1 avatar suhailes1 commented on August 19, 2024

Hi yuslepukhin,
please check below snippet. i got the input and output name from there

Ort::Session session(env, model_path.c_str(), session_options);

// Create an allocator object based on default options to provide memory allocation functions for subsequent operations
Ort::AllocatorWithDefaultOptions allocator;

// Get the number of input nodes
size_t num_input_nodes = session.GetInputCount();

// Get the number of output nodes
size_t num_output_nodes = session.GetOutputCount();

// Get input node name and dimensions
for (int i = 0; i < num_input_nodes; i++) {
    auto input_name = session.GetInputNameAllocated(i, allocator);
    input_node_names.push_back(input_name.get());
    Ort::TypeInfo input_typeinfo = session.GetInputTypeInfo(i);
    auto input_tensorinfo = input_typeinfo.GetTensorTypeAndShapeInfo();
    auto input_dims = input_tensorinfo.GetShape();

    ONNXTensorElementDataType inputType = input_tensorinfo.GetElementType();

    if (input_dims.at(0) == IMR_ERROR)
    {
        std::cout << "[Warning] Got dynamic batch size. Setting output batch size to "
                << BATCH_SIZE << "." << std::endl;
        input_dims.at(0) = BATCH_SIZE;
    }

    input_node_dims.push_back(input_dims);

    std::cout << "[INFO] Input name and shape is: " << input_name.get() << " [";
    for (size_t j = 0; j < input_dims.size(); j++) {
        std::cout << input_dims[j];
        if (j != input_dims.size()-1) {
            std::cout << ",";
        }
    }
    std::cout << ']' << std::endl;
}

// Get output node name
std::vector <vector <int64_t>> output_node_dims;
for (int i = 0; i < num_output_nodes; i++) {
    auto output_name = session.GetOutputNameAllocated(i, allocator);
    output_node_names.push_back(output_name.get());
    Ort::TypeInfo output_typeinfo = session.GetOutputTypeInfo(i);
    auto output_tensorinfo = output_typeinfo.GetTensorTypeAndShapeInfo();
    auto output_dims = output_tensorinfo.GetShape();

    if (output_dims.at(0) == IMR_ERROR)
    {
        std::cout << "[Warning] Got dynamic batch size. Setting output batch size to "
                << BATCH_SIZE << "." << std::endl;
        output_dims.at(0) = BATCH_SIZE;
    }

    output_node_dims.push_back(output_dims);

    std::cout << "[INFO] Output name and shape is: " << output_name.get() << " [";
    for (size_t j = 0; j < output_dims.size(); j++) {
        std::cout << output_dims[j];
        if (j != output_dims.size()-1) {
            std::cout << ",";
        }
    }
    std::cout << ']' << std::endl;
}

from onnxruntime.

suhailes1 avatar suhailes1 commented on August 19, 2024

I refer the code from git. due to my project needs CUDA performance i need to add I/O Binding. so i gone through the reference from the [https://onnxruntime.ai/docs/performance/tune-performance/iobinding.html] ONNX Runtime site.
is there anything i miss from the I/O Binding logic?

from onnxruntime.

suhailes1 avatar suhailes1 commented on August 19, 2024

Hi Tianlei Wu,

Thank u so much. I resolved my issue with the reference which you shared.

from onnxruntime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.