|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +#ifndef USE_ONNXRUNTIME_DLL |
| 5 | +#ifdef __GNUC__ |
| 6 | +#pragma GCC diagnostic push |
| 7 | +#pragma GCC diagnostic ignored "-Wignored-qualifiers" |
| 8 | +#pragma GCC diagnostic ignored "-Wunused-parameter" |
| 9 | +#else |
| 10 | +#pragma warning(push) |
| 11 | +#pragma warning(disable : 4018) /*'expression' : signed/unsigned mismatch */ |
| 12 | +#pragma warning(disable : 4065) /*switch statement contains 'default' but no 'case' labels*/ |
| 13 | +#pragma warning(disable : 4100) |
| 14 | +#pragma warning(disable : 4146) /*unary minus operator applied to unsigned type, result still unsigned*/ |
| 15 | +#pragma warning(disable : 4127) |
| 16 | +#pragma warning(disable : 4244) /*'conversion' conversion from 'type1' to 'type2', possible loss of data*/ |
| 17 | +#pragma warning(disable : 4251) /*'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'*/ |
| 18 | +#pragma warning(disable : 4267) /*'var' : conversion from 'size_t' to 'type', possible loss of data*/ |
| 19 | +#pragma warning(disable : 4305) /*'identifier' : truncation from 'type1' to 'type2'*/ |
| 20 | +#pragma warning(disable : 4307) /*'operator' : integral constant overflow*/ |
| 21 | +#pragma warning(disable : 4309) /*'conversion' : truncation of constant value*/ |
| 22 | +#pragma warning(disable : 4334) /*'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)*/ |
| 23 | +#pragma warning(disable : 4355) /*'this' : used in base member initializer list*/ |
| 24 | +#pragma warning(disable : 4506) /*no definition for inline function 'function'*/ |
| 25 | +#pragma warning(disable : 4800) /*'type' : forcing value to bool 'true' or 'false' (performance warning)*/ |
| 26 | +#pragma warning(disable : 4996) /*The compiler encountered a deprecated declaration.*/ |
| 27 | +#pragma warning(disable : 6011) /*Dereferencing NULL pointer*/ |
| 28 | +#pragma warning(disable : 6387) /*'value' could be '0'*/ |
| 29 | +#pragma warning(disable : 26495) /*Variable is uninitialized.*/ |
| 30 | +#endif |
| 31 | +#include <google/protobuf/message_lite.h> |
| 32 | +#ifdef __GNUC__ |
| 33 | +#pragma GCC diagnostic pop |
| 34 | +#else |
| 35 | +#pragma warning(pop) |
| 36 | +#endif |
| 37 | +#endif |
| 38 | + |
| 39 | +#include "gtest/gtest.h" |
| 40 | +#include "core/session/onnxruntime_cxx_api.h" |
| 41 | +#include "core/session/abi_session_options_impl.h" |
| 42 | + |
| 43 | +TEST(TestSessionOptions, SetIntraOpNumThreadsWithoutEnv) { |
| 44 | + Ort::SessionOptions session_options; |
| 45 | + session_options.SetIntraOpNumThreads(48); |
| 46 | + const auto* ort_session_options = (const OrtSessionOptions*)session_options; |
| 47 | +#ifdef _OPENMP |
| 48 | + ASSERT_EQ(ort_session_options->value.intra_op_param.thread_pool_size, 0); |
| 49 | +#else |
| 50 | + ASSERT_EQ(ort_session_options->value.intra_op_param.thread_pool_size, 48); |
| 51 | +#endif |
| 52 | +} |
| 53 | + |
| 54 | +int main(int argc, char** argv) { |
| 55 | + int status = 0; |
| 56 | + try { |
| 57 | + ::testing::InitGoogleTest(&argc, argv); |
| 58 | + status = RUN_ALL_TESTS(); |
| 59 | + } catch (const std::exception& ex) { |
| 60 | + std::cerr << ex.what(); |
| 61 | + status = -1; |
| 62 | + } |
| 63 | + |
| 64 | +#ifndef USE_ONNXRUNTIME_DLL |
| 65 | + //make memory leak checker happy |
| 66 | + ::google::protobuf::ShutdownProtobufLibrary(); |
| 67 | +#endif |
| 68 | + return status; |
| 69 | +} |
0 commit comments