Repository: opencv/opencv
File: modules/gapi/src/backends/onnx/gonnxbackend.cpp (C++)

Code before:
    std::vector<TensorInfo> out_tensor_info;
    bool is_dynamic = false;
    bool is_postproc = false;

    // G-API <Net> description
    gapi::onnx::detail::ParamDesc params;

    // Input/output tensor information
    std::vector<TensorInfo> getTensorInfo(TensorPosition pos);

    // Run-time data structures
    std::vector<cv::Mat> in_data;
    std::vector<cv::Mat> out_data;

    void Run(const std::vector<cv::Mat>& ins,
             std::vector<cv::Mat>& outs);

    std::vector<std::string> in_names_without_const;

    cv::gapi::onnx::WorkloadTypeOnnxPtr workload_type;
    unsigned int workload_listener_id = 0;
    void setWorkLoadType(const std::string &type);
public:
    explicit ONNXCompiled(const gapi::onnx::detail::ParamDesc &pp);
    ~ONNXCompiled();
    void configureWorkloadType(cv::gapi::onnx::WorkloadTypeOnnxPtr workload);

    // Extract the information about output layer #i
    cv::GMatDesc outMeta(int i) const;

    // Assign input/output info
    std::size_t numInputs() const { return params.num_in; }
    std::size_t numOutputs() const { return params.num_out; }
    void setInput(int i, const cv::Mat &m);
    void setOutput(int idx, cv::Mat &m);
    cv::Mat allocOutput(int i) const;
    // Gets exMat from input
    void extractMat(ONNXCallContext &ctx, const size_t in_idx, Views &views);
    // Extracted cv::Mat from input cv::Mat/cv::MediaFrame
    cv::Mat exMat;
    // Run with the assigned inputs/outputs
    void run();
};

static void addCUDAExecutionProvider(Ort::SessionOptions *session_options,
                                     const cv::gapi::onnx::ep::CUDA &cuda_ep) {
     OrtCUDAProviderOptions options{};
     options.device_id = cuda_ep.device_id;

     try {
        session_options->AppendExecutionProvider_CUDA(options);

Review comment (suggestion):
Might be we can rename it to `listenToWorkloadType()`, if it will not change ONNX workload type state after all the changes.

Code after:
    std::vector<TensorInfo> out_tensor_info;
    bool is_dynamic = false;
    bool is_postproc = false;

    // G-API <Net> description
    gapi::onnx::detail::ParamDesc params;

    // Input/output tensor information
    std::vector<TensorInfo> getTensorInfo(TensorPosition pos);

    // Run-time data structures
    std::vector<cv::Mat> in_data;
    std::vector<cv::Mat> out_data;

    void Run(const std::vector<cv::Mat>& ins,
             std::vector<cv::Mat>& outs);

    std::vector<std::string> in_names_without_const;

    cv::gapi::onnx::WorkloadTypeONNXPtr m_workload_type;
    uint64_t m_workload_listener_id = 0;
    void setWorkloadType(const std::string &type);
public:
    explicit ONNXCompiled(const gapi::onnx::detail::ParamDesc &pp);
    ~ONNXCompiled();
    void listenToWorkloadType(cv::gapi::onnx::WorkloadTypeONNXPtr workload);

    // Extract the information about output layer #i
    cv::GMatDesc outMeta(int i) const;

    // Assign input/output info
    std::size_t numInputs() const { return params.num_in; }
    std::size_t numOutputs() const { return params.num_out; }
    void setInput(int i, const cv::Mat &m);
    void setOutput(int idx, cv::Mat &m);
    cv::Mat allocOutput(int i) const;
    // Gets exMat from input
    void extractMat(ONNXCallContext &ctx, const size_t in_idx, Views &views);
    // Extracted cv::Mat from input cv::Mat/cv::MediaFrame
    cv::Mat exMat;
    // Run with the assigned inputs/outputs
    void run();
};

static void addCUDAExecutionProvider(Ort::SessionOptions *session_options,
                                     const cv::gapi::onnx::ep::CUDA &cuda_ep) {
     OrtCUDAProviderOptions options{};
     options.device_id = cuda_ep.device_id;

     try {
        session_options->AppendExecutionProvider_CUDA(options);