Skip to content

Commit

Permalink
Remove references to the outdated CUDA EP factory method (#21549)
Browse files Browse the repository at this point in the history
The function "OrtSessionOptionsAppendExecutionProvider_CUDA" is
deprecated.
  • Loading branch information
snnn authored Jul 30, 2024
1 parent 07d3be5 commit 82036b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion onnxruntime/test/global_thread_pools/test_inference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ static Ort::Session GetSessionObj(Ort::Env& env, T model_uri, int provider_type)

if (provider_type == 1) {
#ifdef USE_CUDA
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CUDA(session_options, 0));
OrtCUDAProviderOptionsV2* options;
Ort::ThrowOnError(Ort::GetApi().CreateCUDAProviderOptions(&options));
session_options.AppendExecutionProvider_CUDA_V2(*options);
std::cout << "Running simple inference with cuda provider" << std::endl;
#else
return Ort::Session(nullptr);
Expand Down
20 changes: 15 additions & 5 deletions onnxruntime/test/shared_lib/test_inference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,9 @@ TEST(CApiTest, get_allocator_cpu) {
#ifdef USE_CUDA
TEST(CApiTest, get_allocator_cuda) {
Ort::SessionOptions session_options;
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CUDA(session_options, 0));
OrtCUDAProviderOptionsV2* options;
Ort::ThrowOnError(Ort::GetApi().CreateCUDAProviderOptions(&options));
session_options.AppendExecutionProvider_CUDA_V2(*options);
Ort::Session session(*ort_env, NAMED_AND_ANON_DIM_PARAM_URI, session_options);

Ort::MemoryInfo info_cuda("Cuda", OrtAllocatorType::OrtArenaAllocator, 0, OrtMemTypeDefault);
Expand Down Expand Up @@ -2076,7 +2078,9 @@ TEST(CApiTest, io_binding_cuda) {
#ifdef USE_TENSORRT
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_Tensorrt(session_options, 0));
#else
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CUDA(session_options, 0));
OrtCUDAProviderOptionsV2* options;
Ort::ThrowOnError(Ort::GetApi().CreateCUDAProviderOptions(&options));
session_options.AppendExecutionProvider_CUDA_V2(*options);
#endif
Ort::Session session(*ort_env, MODEL_URI, session_options);

Expand Down Expand Up @@ -3438,7 +3442,9 @@ TEST(CApiTest, AllocateInitializersFromNonArenaMemory) {
Ort::SessionOptions session_options;

#ifdef USE_CUDA
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CUDA(session_options, 0));
OrtCUDAProviderOptionsV2* options;
Ort::ThrowOnError(Ort::GetApi().CreateCUDAProviderOptions(&options));
session_options.AppendExecutionProvider_CUDA_V2(*options);
#else
// arena is enabled but the sole initializer will still be allocated from non-arena memory
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CPU(session_options, 1));
Expand Down Expand Up @@ -3890,7 +3896,9 @@ TEST(CApiTest, GitHubIssue10179) {
try {
const auto* model_path = MODEL_URI;
Ort::SessionOptions session_options{};
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CUDA(session_options, 0));
OrtCUDAProviderOptionsV2* options;
Ort::ThrowOnError(Ort::GetApi().CreateCUDAProviderOptions(&options));
session_options.AppendExecutionProvider_CUDA_V2(*options);
Ort::Session session{*ort_env, model_path, session_options};
} catch (const std::exception& e) {
std::cerr << "exception: " << e.what() << "\n";
Expand Down Expand Up @@ -3920,7 +3928,9 @@ TEST(CApiTest, GitHubIssue10179) {
TEST(CApiTest, TestCudaMemcpyToHostWithSequenceTensors) {
const auto* model_path = SEQUENCE_MODEL_URI_2;
Ort::SessionOptions session_options{};
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CUDA(session_options, 0));
OrtCUDAProviderOptionsV2* options;
Ort::ThrowOnError(Ort::GetApi().CreateCUDAProviderOptions(&options));
session_options.AppendExecutionProvider_CUDA_V2(*options);
Ort::Session session{*ort_env, model_path, session_options};

Ort::MemoryInfo info("Cpu", OrtDeviceAllocator, 0, OrtMemTypeDefault);
Expand Down
5 changes: 3 additions & 2 deletions onnxruntime/test/shared_lib/test_model_loading.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ TEST(CApiTest, model_from_array) {
create_session(so);

#ifdef USE_CUDA
// test with CUDA provider when using onnxruntime as dll
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CUDA(so, 0));
OrtCUDAProviderOptionsV2* options;
Ort::ThrowOnError(Ort::GetApi().CreateCUDAProviderOptions(&options));
so.AppendExecutionProvider_CUDA_V2(*options);
create_session(so);
#endif
}
Expand Down

0 comments on commit 82036b0

Please sign in to comment.