diff --git a/onnxruntime/contrib_ops/cpu/activations.h b/onnxruntime/contrib_ops/cpu/activations.h index ecfe3cbe43..541016396d 100644 --- a/onnxruntime/contrib_ops/cpu/activations.h +++ b/onnxruntime/contrib_ops/cpu/activations.h @@ -89,12 +89,12 @@ class FastGelu : public OpKernel { int64_t elem_count = X->Shape().Size(); const auto coefficient = kAlpha * kGamma; if (elem_count > task_count) { - tp->ParallelFor(task_count, [ input, + tp->SimpleParallelFor(static_cast(task_count), [ input, output, elem_count, task_count, kAlpha = this->kAlpha, - coefficient ](int32_t i) { + coefficient ](std::ptrdiff_t i) { int64_t elem_inx_start = i * elem_count / task_count; int64_t elem_inx_end = (i + 1) * elem_count / task_count; for (int64_t elem_inx = elem_inx_start; elem_inx < elem_inx_end; elem_inx++) { diff --git a/onnxruntime/core/platform/windows/env.cc b/onnxruntime/core/platform/windows/env.cc index 2be08d8baf..df51fc71e0 100644 --- a/onnxruntime/core/platform/windows/env.cc +++ b/onnxruntime/core/platform/windows/env.cc @@ -214,13 +214,7 @@ class WindowsEnv : public Env { return Status::OK(); } -<<<<<<< HEAD - Status MapFileIntoMemory( - const PathChar*, FileOffsetType, size_t, - MappedMemoryPtr&) const override { -======= Status MapFileIntoMemory(const ORTCHAR_T*, FileOffsetType, size_t, MappedMemoryPtr&) const override { ->>>>>>> origin/master return ORT_MAKE_STATUS(ONNXRUNTIME, NOT_IMPLEMENTED, "MapFileIntoMemory is not implemented on Windows."); } @@ -356,7 +350,7 @@ class WindowsEnv : public Env { // adapted from MSVC STL std::filesystem::canonical() implementation // https://github.com/microsoft/STL/blob/ed3cbf36416a385828e7a5987ca52cb42882d84b/stl/inc/filesystem#L2986 - ScopedFileHandle file_handle{CreateFileW( + wil::unique_hfile file_handle{CreateFileW( path.c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, @@ -365,8 +359,10 @@ class WindowsEnv : public Env { FILE_FLAG_BACKUP_SEMANTICS, nullptr)}; - ORT_RETURN_IF_NOT( - file_handle.IsValid(), "CreateFile() failed: ", GetLastError()); + if (file_handle.get() == INVALID_HANDLE_VALUE) { + const int err = GetLastError(); + return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "open file ", ToMBString(path), " fail, errcode = ", err); + } constexpr DWORD initial_buffer_size = MAX_PATH; std::vector result_buffer{}; @@ -374,7 +370,7 @@ class WindowsEnv : public Env { while (true) { const DWORD result_length = GetFinalPathNameByHandleW( - file_handle.Get(), + file_handle.get(), result_buffer.data(), static_cast(result_buffer.size()), 0); diff --git a/onnxruntime/test/python/onnxruntime_test_python.py b/onnxruntime/test/python/onnxruntime_test_python.py index cd90e7c3a7..a51e69caf7 100644 --- a/onnxruntime/test/python/onnxruntime_test_python.py +++ b/onnxruntime/test/python/onnxruntime_test_python.py @@ -12,19 +12,6 @@ from helper import get_name class TestInferenceSession(unittest.TestCase): - def get_name(self, name): - if os.path.exists(name): - return name - rel = os.path.join("testdata", name) - if os.path.exists(rel): - return rel - this = os.path.dirname(__file__) - data = os.path.join(this, "..", "testdata") - res = os.path.join(data, name) - if os.path.exists(res): - return res - raise FileNotFoundError("Unable to find '{0}' or '{1}' or '{2}'".format(name, rel, res)) - def run_model(self, session_object, run_options): x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=np.float32) input_name = session_object.get_inputs()[0].name @@ -66,7 +53,7 @@ class TestInferenceSession(unittest.TestCase): def testSessionProviders(self): if 'CUDAExecutionProvider' in onnxrt.get_available_providers(): # create session from scratch, but constrain it to only use the CPU. - sess = onnxrt.InferenceSession(self.get_name("mul_1.onnx"), providers=['CPUExecutionProvider']) + sess = onnxrt.InferenceSession(get_name("mul_1.onnx"), providers=['CPUExecutionProvider']) self.assertEqual(['CPUExecutionProvider'], sess.get_providers()) def testRunModel(self): @@ -117,7 +104,7 @@ class TestInferenceSession(unittest.TestCase): np.testing.assert_allclose(output_expected, res[0], rtol=1e-05, atol=1e-08) def testRunModel2Contiguous(self): - sess = onnxrt.InferenceSession(self.get_name("matmul_1.onnx")) + sess = onnxrt.InferenceSession(get_name("matmul_1.onnx")) x = np.array([[2.0, 1.0], [4.0, 3.0], [6.0, 5.0]], dtype=np.float32)[:, [1, 0]] input_name = sess.get_inputs()[0].name self.assertEqual(input_name, "X") @@ -138,7 +125,7 @@ class TestInferenceSession(unittest.TestCase): so = onnxrt.SessionOptions() so.log_verbosity_level = 1 so.logid = "MultiThreadsTest" - sess = onnxrt.InferenceSession(self.get_name("mul_1.onnx"), sess_options=so) + sess = onnxrt.InferenceSession(get_name("mul_1.onnx"), sess_options=so) ro1 = onnxrt.RunOptions() ro1.logid = "thread1" t1 = threading.Thread(target=self.run_model, args=(sess, ro1)) @@ -219,7 +206,7 @@ class TestInferenceSession(unittest.TestCase): np.testing.assert_equal(output_expected, res[0]) def testStringInput1(self): - sess = onnxrt.InferenceSession(self.get_name("identity_string.onnx")) + sess = onnxrt.InferenceSession(get_name("identity_string.onnx")) x = np.array(['this', 'is', 'identity', 'test'], dtype=np.str).reshape((2, 2)) x_name = sess.get_inputs()[0].name @@ -240,7 +227,7 @@ class TestInferenceSession(unittest.TestCase): np.testing.assert_equal(x, res[0]) def testStringInput2(self): - sess = onnxrt.InferenceSession(self.get_name("identity_string.onnx")) + sess = onnxrt.InferenceSession(get_name("identity_string.onnx")) x = np.array(['Olá', '你好', '여보세요', 'hello'], dtype=np.unicode).reshape((2, 2)) x_name = sess.get_inputs()[0].name @@ -282,7 +269,7 @@ class TestInferenceSession(unittest.TestCase): np.testing.assert_equal(x, res[0].astype('|S8')) def testInputObject(self): - sess = onnxrt.InferenceSession(self.get_name("identity_string.onnx")) + sess = onnxrt.InferenceSession(get_name("identity_string.onnx")) x = np.array(['this', 'is', 'identity', 'test'], object).reshape((2, 2)) x_name = sess.get_inputs()[0].name @@ -303,7 +290,7 @@ class TestInferenceSession(unittest.TestCase): np.testing.assert_equal(x, res[0]) def testInputVoid(self): - sess = onnxrt.InferenceSession(self.get_name("identity_string.onnx")) + sess = onnxrt.InferenceSession(get_name("identity_string.onnx")) x = np.array([b'this', b'is', b'identity', b'test'], np.void).reshape((2, 2)) x_name = sess.get_inputs()[0].name @@ -327,7 +314,7 @@ class TestInferenceSession(unittest.TestCase): np.testing.assert_equal(expr, res[0]) def testZipMapStringFloat(self): - sess = onnxrt.InferenceSession(self.get_name("zipmap_stringfloat.onnx")) + sess = onnxrt.InferenceSession(get_name("zipmap_stringfloat.onnx")) x = np.array([1.0, 0.0, 3.0, 44.0, 23.0, 11.0], dtype=np.float32).reshape((2, 3)) x_name = sess.get_inputs()[0].name @@ -353,7 +340,7 @@ class TestInferenceSession(unittest.TestCase): self.assertEqual(output_expected, res[0]) def testZipMapInt64Float(self): - sess = onnxrt.InferenceSession(self.get_name("zipmap_int64float.onnx")) + sess = onnxrt.InferenceSession(get_name("zipmap_int64float.onnx")) x = np.array([1.0, 0.0, 3.0, 44.0, 23.0, 11.0], dtype=np.float32).reshape((2, 3)) x_name = sess.get_inputs()[0].name @@ -392,7 +379,7 @@ class TestInferenceSession(unittest.TestCase): def testProfilerWithSessionOptions(self): so = onnxrt.SessionOptions() so.enable_profiling = True - sess = onnxrt.InferenceSession(self.get_name("mul_1.onnx"), sess_options=so) + sess = onnxrt.InferenceSession(get_name("mul_1.onnx"), sess_options=so) x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=np.float32) sess.run([], {'X': x}) profile_file = sess.end_profiling() @@ -407,7 +394,7 @@ class TestInferenceSession(unittest.TestCase): self.assertTrue(']' in lines[8]) def testDictVectorizer(self): - sess = onnxrt.InferenceSession(self.get_name("pipeline_vectorize.onnx")) + sess = onnxrt.InferenceSession(get_name("pipeline_vectorize.onnx")) input_name = sess.get_inputs()[0].name self.assertEqual(input_name, "float_input") input_type = str(sess.get_inputs()[0].type) @@ -521,7 +508,7 @@ class TestInferenceSession(unittest.TestCase): res = sess.run([], {'input1:0': a, 'input:0': b}) def testSequenceLength(self): - sess = onnxrt.InferenceSession(self.get_name("sequence_length.onnx")) + sess = onnxrt.InferenceSession(get_name("sequence_length.onnx")) x = [ np.array([1.0, 0.0, 3.0, 44.0, 23.0, 11.0], dtype=np.float32).reshape((2, 3)), np.array([1.0, 0.0, 3.0, 44.0, 23.0, 11.0], dtype=np.float32).reshape((2, 3)) @@ -542,7 +529,7 @@ class TestInferenceSession(unittest.TestCase): self.assertEqual(output_expected, res[0]) def testSequenceConstruct(self): - sess = onnxrt.InferenceSession(self.get_name("sequence_construct.onnx")) + sess = onnxrt.InferenceSession(get_name("sequence_construct.onnx")) self.assertEqual(sess.get_inputs()[0].type, 'tensor(int64)') self.assertEqual(sess.get_inputs()[1].type, 'tensor(int64)') diff --git a/orttraining/orttraining/models/pipeline_poc/main.cc b/orttraining/orttraining/models/pipeline_poc/main.cc index 84cdaf6717..a80aa08e9f 100644 --- a/orttraining/orttraining/models/pipeline_poc/main.cc +++ b/orttraining/orttraining/models/pipeline_poc/main.cc @@ -96,9 +96,11 @@ int main(int argc, char* argv[]) { 0, //session_log_verbosity_level 5, //max_num_graph_transformation_steps TransformerLevel::Level1, //graph_optimization_level - 0, //intra_op_num_threads - 0, //inter_op_num_threads - overrides //free_dimension_overrides + {}, //intra_op_param + {}, //inter_op_param + overrides, //free_dimension_overrides + true, //use_per_session_threads + true //thread_pool_allow_spinning }; InferenceSession session_object{so, *env}; diff --git a/orttraining/orttraining/models/runner/data_loader.cc b/orttraining/orttraining/models/runner/data_loader.cc index 63523729e3..1376db0629 100644 --- a/orttraining/orttraining/models/runner/data_loader.cc +++ b/orttraining/orttraining/models/runner/data_loader.cc @@ -68,7 +68,7 @@ DataLoader::DataLoader(const MapStringToString& input_name_map, } data_loader_thread_pool_ = onnxruntime::make_unique( - "DataLoaderPool", thread_pool_size_); + &onnxruntime::Env::Default(), onnxruntime::ThreadOptions(), ORT_TSTR("DataLoaderPool"), thread_pool_size_, true); } Status DataLoader::InitializeDataSetIndex(size_t initial_data_set_index) { diff --git a/orttraining/orttraining/models/runner/training_runner.cc b/orttraining/orttraining/models/runner/training_runner.cc index bdd312c42d..4879d4cdd9 100644 --- a/orttraining/orttraining/models/runner/training_runner.cc +++ b/orttraining/orttraining/models/runner/training_runner.cc @@ -33,9 +33,11 @@ static SessionOptions SESSION_OPTION = { 0, //session_log_verbosity_level 5, //max_num_graph_transformation_steps TransformerLevel::Level1, //graph_optimization_level - 0, //intra_op_num_threads - 0, //inter_op_num_threads - overrides //free_dimension_overrides + {}, //intra_op_param + {}, //inter_op_param + overrides, //free_dimension_overrides + true, //use_per_session_threads + true //thread_pool_allow_spinning }; TrainingRunner::TrainingRunner(Parameters params, const Environment& env) diff --git a/orttraining/orttraining/test/gradient/gradient_ops_test.cc b/orttraining/orttraining/test/gradient/gradient_ops_test.cc index 0dd17510e2..7f83c33f5e 100644 --- a/orttraining/orttraining/test/gradient/gradient_ops_test.cc +++ b/orttraining/orttraining/test/gradient/gradient_ops_test.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include "gtest/gtest.h" #include "core/framework/random_seed.h" diff --git a/orttraining/orttraining/test/graph/gradient_graph_builder_test.cc b/orttraining/orttraining/test/graph/gradient_graph_builder_test.cc index 937b294e57..60529f7c13 100644 --- a/orttraining/orttraining/test/graph/gradient_graph_builder_test.cc +++ b/orttraining/orttraining/test/graph/gradient_graph_builder_test.cc @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +#include #include "gtest/gtest.h" #include "orttraining/core/optimizer/gist_encode_decode.h"