Skip to content

Commit 07bd4ef

Browse files
authored
Upgrade optional implementation to https://github.com/martinmoene/optional-lite. (microsoft#5563)
1 parent 67d7e39 commit 07bd4ef

File tree

8 files changed

+100
-71
lines changed

8 files changed

+100
-71
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@
6565
[submodule "cmake/external/onnx-tensorrt"]
6666
path = cmake/external/onnx-tensorrt
6767
url = https://github.com/onnx/onnx-tensorrt.git
68+
[submodule "cmake/external/optional-lite"]
69+
path = cmake/external/optional-lite
70+
url = https://github.com/martinmoene/optional-lite.git

ThirdPartyNotices.txt

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -848,22 +848,16 @@ THE POSSIBILITY OF SUCH DAMAGE.
848848

849849
_____
850850

851-
Microsoft/GSL
851+
gsl-lite
852852

853+
gsl-lite is based on GSL: Guidelines Support Library.
854+
For more information see https://github.com/martinmoene/gsl-lite
855+
856+
Copyright (c) 2015 Martin Moene
853857
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
854858

855859
This code is licensed under the MIT License (MIT).
856860

857-
Permission is hereby granted, free of charge, to any person obtaining a copy
858-
of this software and associated documentation files (the "Software"), to deal
859-
in the Software without restriction, including without limitation the rights
860-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
861-
of the Software, and to permit persons to whom the Software is furnished to do
862-
so, subject to the following conditions:
863-
864-
The above copyright notice and this permission notice shall be included in all
865-
copies or substantial portions of the Software.
866-
867861
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
868862
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
869863
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -1657,7 +1651,7 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
16571651
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16581652
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16591653

1660-
____
1654+
_____
16611655

16621656
Distributed Machine Learning Common Codebase
16631657

@@ -1881,7 +1875,7 @@ DLPack: Open In Memory Tensor Structure
18811875
See the License for the specific language governing permissions and
18821876
limitations under the License.
18831877

1884-
____
1878+
_____
18851879

18861880
HowardHinnant/date
18871881

@@ -1917,7 +1911,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19171911
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19181912
SOFTWARE.
19191913

1920-
____
1914+
_____
19211915

19221916
TVM Open Deep Learning Compiler Stack
19231917

@@ -2204,7 +2198,7 @@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22042198
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22052199
--------------------------------------------------------------------------------
22062200

2207-
____
2201+
_____
22082202

22092203
FreeBSD: getopt.c file
22102204

@@ -3048,7 +3042,7 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30483042
DEALINGS IN THE SOFTWARE.
30493043

30503044

3051-
-----
3045+
_____
30523046

30533047
JDAI-CV/DNNLibrary
30543048

@@ -3255,7 +3249,7 @@ JDAI-CV/DNNLibrary
32553249
limitations under the License.
32563250

32573251

3258-
-----
3252+
_____
32593253

32603254
google/flatbuffers
32613255

@@ -3463,7 +3457,7 @@ google/flatbuffers
34633457
limitations under the License.
34643458

34653459

3466-
-----
3460+
_____
34673461

34683462
google/glog
34693463

@@ -3533,7 +3527,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35333527
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35343528
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35353529

3536-
----
3530+
_____
35373531

35383532
abseil-cpp
35393533
https://github.com/abseil/abseil-cpp
@@ -3741,7 +3735,7 @@ https://github.com/abseil/abseil-cpp
37413735
limitations under the License.
37423736

37433737

3744-
-----
3738+
_____
37453739

37463740
NVlabs/cub
37473741

@@ -3770,7 +3764,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37703764
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37713765
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37723766

3773-
-----
3767+
_____
37743768

37753769
microsoft/wil
37763770

@@ -3796,7 +3790,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37963790
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37973791
SOFTWARE
37983792

3799-
-----
3793+
_____
38003794

38013795
nlohmann/json
38023796

@@ -3822,7 +3816,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38223816
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38233817
SOFTWARE.
38243818

3825-
-----
3819+
_____
38263820

38273821
dcleblanc/SafeInt
38283822

@@ -3848,7 +3842,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38483842
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38493843
SOFTWARE.
38503844

3851-
-----
3845+
_____
38523846
Open MPI
38533847

38543848
3-Clause BSD License
@@ -3954,7 +3948,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39543948
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39553949
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39563950

3957-
-----
3951+
_____
39583952

39593953
The Android Open Source Project
39603954

@@ -4293,7 +4287,7 @@ libprotobuf-mutator
42934287
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42944288
POSSIBILITY OF SUCH DAMAGE.
42954289

4296-
--
4290+
_____
42974291

42984292
mpi4py
42994293
https://github.com/mpi4py/mpi4py/
@@ -4805,7 +4799,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
48054799
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
48064800
PERFORMANCE OF THIS SOFTWARE.
48074801

4808-
-----
4802+
_____
48094803

48104804
MurmurHash3
48114805

@@ -4820,7 +4814,7 @@ SMHasher test suite used to verify them.
48204814
SMHasher is released under the MIT license.
48214815
All MurmurHash versions are public domain software, and the author disclaims all copyright to their code.
48224816

4823-
-----
4817+
_____
48244818

48254819
gtest-ios-framework
48264820

@@ -4847,4 +4841,38 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
48474841
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
48484842
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48494843

4850-
-----
4844+
_____
4845+
4846+
optional-lite
4847+
4848+
Copyright (c) 2014-2018 Martin Moene
4849+
4850+
https://github.com/martinmoene/optional-lite
4851+
4852+
Distributed under the Boost Software License, Version 1.0.
4853+
4854+
Boost Software License - Version 1.0 - August 17th, 2003
4855+
4856+
Permission is hereby granted, free of charge, to any person or organization
4857+
obtaining a copy of the software and accompanying documentation covered by
4858+
this license (the "Software") to use, reproduce, display, distribute,
4859+
execute, and transmit the Software, and to prepare derivative works of the
4860+
Software, and to permit third-parties to whom the Software is furnished to
4861+
do so, all subject to the following:
4862+
4863+
The copyright notices in the Software and this entire statement, including
4864+
the above license grant, this restriction and the following disclaimer,
4865+
must be included in all copies of the Software, in whole or in part, and
4866+
all derivative works of the Software, unless such copies or derivative
4867+
works are solely in the form of machine-executable object code generated by
4868+
a source language processor.
4869+
4870+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4871+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4872+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
4873+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
4874+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
4875+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
4876+
DEALINGS IN THE SOFTWARE.
4877+
4878+
_____

cgmanifests/submodules/cgmanifest.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,16 @@
431431
"comments": "git submodule at cmake/external/onnx-tensorrt/third_party/onnx/third_party/pybind11/tools/clang"
432432
}
433433
},
434+
{
435+
"component": {
436+
"type": "git",
437+
"git": {
438+
"commitHash": "4acf4553baa886e10e6613fe1452b706b0250e78",
439+
"repositoryUrl": "https://github.com/martinmoene/optional-lite.git"
440+
},
441+
"comments": "git submodule at cmake/external/optional-lite"
442+
}
443+
},
434444
{
435445
"component": {
436446
"type": "git",

cmake/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ set(SAFEINT_INCLUDE_DIR ${REPO_ROOT}/cmake/external/SafeInt)
621621
add_library(safeint_interface INTERFACE)
622622
target_include_directories(safeint_interface INTERFACE ${SAFEINT_INCLUDE_DIR})
623623

624+
set(OPTIONAL_LITE_INCLUDE_DIR ${REPO_ROOT}/cmake/external/optional-lite/include)
625+
if(onnxruntime_DISABLE_EXCEPTIONS)
626+
add_compile_definitions(optional_CONFIG_NO_EXCEPTIONS=1)
627+
endif()
628+
624629
if(NOT TARGET re2::re2)
625630
add_subdirectory(external/re2 EXCLUDE_FROM_ALL)
626631
set_target_properties(re2 PROPERTIES FOLDER "External/re2")

cmake/external/optional-lite

Submodule optional-lite added at 4acf455

cmake/onnxruntime_common.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ endif()
100100
onnxruntime_add_include_to_target(onnxruntime_common date_interface wil)
101101
target_include_directories(onnxruntime_common
102102
PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS}
103-
# safeint is part of onnxruntime_common public interface, so we want to propagate its includes
104-
PUBLIC $<TARGET_PROPERTY:safeint_interface,INTERFACE_INCLUDE_DIRECTORIES>)
103+
# propagate include directories of dependencies that are part of public interface
104+
PUBLIC
105+
$<TARGET_PROPERTY:safeint_interface,INTERFACE_INCLUDE_DIRECTORIES>
106+
${OPTIONAL_LITE_INCLUDE_DIR})
105107

106108
if(NOT WIN32)
107109
target_include_directories(onnxruntime_common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/external/nsync/public")

include/onnxruntime/core/common/optional.h

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,22 @@
33

44
#pragma once
55

6-
#include "core/common/common.h"
6+
#include <nonstd/optional.hpp>
77

88
namespace onnxruntime {
9-
// This is a version of std::optional with limited functionality and plenty of
10-
// room to improve. We should use std::optional when we move to C++17.
11-
template <typename T>
12-
class optional {
13-
public:
14-
optional() : has_value_{false}, value_{} {}
15-
16-
optional(const optional&) = default;
17-
optional& operator=(const optional&) = default;
18-
optional(optional&&) = default;
19-
optional& operator=(optional&&) = default;
20-
21-
optional(T value) : has_value_{true}, value_{value} {}
22-
optional& operator=(T value) {
23-
has_value_ = true;
24-
value_ = value;
25-
return *this;
26-
}
27-
28-
bool has_value() const { return has_value_; }
29-
const T& value() const {
30-
ORT_ENFORCE(has_value_);
31-
return value_;
32-
}
33-
T& value() {
34-
ORT_ENFORCE(has_value_);
35-
return value_;
36-
}
37-
38-
private:
39-
bool has_value_;
40-
T value_;
41-
};
9+
10+
using nonstd::optional;
11+
12+
#ifndef ORT_NO_EXCEPTIONS
13+
using nonstd::bad_optional_access;
14+
#endif
15+
16+
using nonstd::nullopt;
17+
using nonstd::nullopt_t;
18+
19+
using nonstd::in_place;
20+
using nonstd::in_place_t;
21+
22+
using nonstd::make_optional;
23+
4224
} // namespace onnxruntime

include/onnxruntime/core/platform/threadpool.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ limitations under the License.
2222
#include <memory>
2323
#include "core/common/common.h"
2424
#include "core/platform/env.h"
25-
#include "core/common/optional.h"
2625

2726
#include <functional>
2827
#include <memory>
@@ -81,7 +80,7 @@ class ThreadPool {
8180
// synchronously if it cannot be enqueued. This will occur if the thread pool's
8281
// degree-of-parallelism is 1, but it may also occur for implementation-dependent
8382
// reasons such as if queues used for buffering work are full.
84-
static void Schedule(ThreadPool *tp,
83+
static void Schedule(ThreadPool* tp,
8584
std::function<void()> fn) {
8685
if (tp) {
8786
tp->Schedule(fn);
@@ -108,7 +107,7 @@ class ThreadPool {
108107
}
109108

110109
static void TryParallelFor(ThreadPool* tp, std::ptrdiff_t total, const TensorOpCost& cost_per_unit,
111-
const std::function<void(std::ptrdiff_t first, std::ptrdiff_t last)>& fn);
110+
const std::function<void(std::ptrdiff_t first, std::ptrdiff_t last)>& fn);
112111

113112
// Directly schedule the 'total' tasks to the underlying threadpool, without
114113
// cutting them by halves
@@ -221,8 +220,8 @@ class ThreadPool {
221220
// Provide a hint to the caller for whether or not to parallelize
222221
// work. This lets a caller switch to a sequential version of an
223222
// algorithm rather than using calls via the ParallelFor functions.
224-
225-
static bool ShouldParallelize(const ThreadPool *tp);
223+
224+
static bool ShouldParallelize(const ThreadPool* tp);
226225

227226
// Return the degree of parallelism that code should assume when using the thread pool.
228227
// It decouples the degree of parallelism for use with the thread pool from
@@ -262,7 +261,6 @@ class ThreadPool {
262261
void ParallelForFixedBlockSizeScheduling(std::ptrdiff_t total, std::ptrdiff_t block_size,
263262
const std::function<void(std::ptrdiff_t, std::ptrdiff_t)>& fn);
264263

265-
266264
// Return whether or not the calling thread should run a loop of
267265
// num_iterations divided in chunks of block_size in parallel. If not,
268266
// the caller should run the loop sequentially.

0 commit comments

Comments
 (0)