Created
November 16, 2019 02:06
-
-
Save pranavsharma/11a1468368a80d6b94a4d9f67b506861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST(InferenceSessionTests, TestIssue2404) { | |
string model_uri = "testdata/test_model.onnx"; | |
SessionOptions so; | |
//so.session_logid = "InferenceSessionTests." + log_str; | |
//so.session_log_verbosity_level = 1; // change to 1 for detailed logging | |
InferenceSession session_object{so, &DefaultLoggingManager()}; | |
CUDAExecutionProviderInfo epi; | |
epi.device_id = 0; | |
EXPECT_TRUE(session_object.RegisterExecutionProvider(onnxruntime::make_unique<CUDAExecutionProvider>(epi)).IsOK()); | |
ASSERT_TRUE(session_object.Load(model_uri).IsOK()); | |
ASSERT_TRUE(session_object.Initialize().IsOK()); | |
unique_ptr<IOBinding> io_binding; | |
Status st = session_object.NewIOBinding(&io_binding); | |
ASSERT_TRUE(st.IsOK()); | |
auto input_allocator = io_binding->GetCPUAllocator(0, kCudaExecutionProvider); | |
std::vector<float> values_mul_x(32 * 3 * 112 * 112, 1.0f); | |
OrtValue input_ml_value_A; | |
std::vector<int64_t> dims_mul_x_A = {32, 3, 112, 112}; | |
CreateMLValue<float>(input_allocator, dims_mul_x_A, values_mul_x, &input_ml_value_A); | |
io_binding->BindInput("input1", input_ml_value_A); | |
std::vector<int64_t> expected_output_dims = {32, 1000, 1, 1}; | |
OrtValue output_ml_value; | |
AllocateMLValue<float>(TestCudaExecutionProvider()->GetAllocator(0, OrtMemTypeDefault), expected_output_dims, | |
&output_ml_value); | |
io_binding->BindOutput("output1", output_ml_value); | |
ASSERT_TRUE(io_binding->SynchronizeInputs().IsOK()); | |
for (int i = 0; i < 10; ++i) { | |
st = session_object.Run(*io_binding.get()); | |
} | |
auto start = chrono::steady_clock::now(); | |
for (int i = 0; i < 1; ++i) { | |
st = session_object.Run(*io_binding.get()); | |
if (!st.IsOK()) { | |
std::cout << "Problem...\n"; | |
break; | |
} | |
} | |
auto end = chrono::steady_clock::now(); | |
cout << "Elapsed time in microseconds : " | |
<< chrono::duration_cast<chrono::microseconds>(end - start).count() | |
<< " µs" << endl; | |
cout << "Elapsed time in milliseconds : " | |
<< chrono::duration_cast<chrono::milliseconds>(end - start).count() | |
<< " ms" << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can run this as part of inference_session_test.cc.