Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6a2a7b1
Update Cast to limit implemented types.
edgchen1 Jan 16, 2021
44a65ca
Remove special case handling of string and float16.
edgchen1 Jan 21, 2021
e93577e
Add Mp11 submodule.
edgchen1 Jan 21, 2021
79caf38
Add Mp11 to cgmanifest.json.
edgchen1 Jan 21, 2021
01138b5
Fix generate_submodule_cgmanifest.py Windows issues.
edgchen1 Jan 21, 2021
987038d
Update CMake files to use Mp11 submodule.
edgchen1 Jan 22, 2021
02d754a
Revert "Fix generate_submodule_cgmanifest.py Windows issues."
edgchen1 Jan 22, 2021
a683f09
Add MLFloat(float) ctor, change from union to struct.
edgchen1 Jan 22, 2021
541ecb7
Move MLTypeCallDispatcher2 into data_types_internal.h, clean up.
edgchen1 Jan 22, 2021
9f21483
Initial implemented type utils.
edgchen1 Jan 22, 2021
47bd1c5
Move type_list.h.
edgchen1 Jan 22, 2021
ea2bceb
Improve op arg type specification, add global override list.
edgchen1 Jan 23, 2021
f781a85
Clean up, renaming.
edgchen1 Jan 25, 2021
9ccb5e9
Merge remote-tracking branch 'origin/master' into edgchen1/type_reduc…
edgchen1 Jan 25, 2021
c462e4e
Revert unintentional changes from reduced op build.
edgchen1 Jan 25, 2021
23ff415
Fix warning from dispatcher with empty Types, some clean up.
edgchen1 Jan 26, 2021
b0532b6
Add kernel type constraints helper supporting type lists.
edgchen1 Jan 26, 2021
0a38576
Add location for specifying type overrides.
edgchen1 Jan 26, 2021
d608422
Update IsInf.
edgchen1 Jan 26, 2021
1564270
Update documentation in op_kernel_type_control.h.
edgchen1 Jan 26, 2021
a700c84
Clean up.
edgchen1 Jan 26, 2021
0610765
Merge remote-tracking branch 'origin/master' into edgchen1/type_reduc…
edgchen1 Jan 26, 2021
882857a
Fix include order.
edgchen1 Jan 26, 2021
39135b6
Fix CMake issue.
edgchen1 Jan 26, 2021
e3d1edb
Address PR comments.
edgchen1 Jan 27, 2021
5a02162
Try to fix build.
edgchen1 Jan 27, 2021
a2f9529
Rename type to types.
edgchen1 Jan 27, 2021
d708c24
Fix build issues.
edgchen1 Jan 27, 2021
af07268
Try to fix Windows build.
edgchen1 Jan 27, 2021
8273e1f
Add .inc file in CMake.
edgchen1 Jan 27, 2021
7ea56bd
Add Op domain to type control infrastructure.
edgchen1 Jan 27, 2021
2b73b13
Add support for providers when specifying supported types.
edgchen1 Jan 28, 2021
0d55a1b
Merge remote-tracking branch 'origin/master' into edgchen1/type_reduc…
edgchen1 Jan 28, 2021
be93033
Fix GPU build issue.
edgchen1 Jan 28, 2021
591e9e2
More build fixes.
edgchen1 Jan 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
[submodule "cmake/external/optional-lite"]
path = cmake/external/optional-lite
url = https://github.com/martinmoene/optional-lite.git
[submodule "cmake/external/mp11"]
path = cmake/external/mp11
url = https://github.com/boostorg/mp11.git
[submodule "cmake/external/coremltools"]
path = cmake/external/coremltools
url = https://github.com/apple/coremltools.git
Expand Down
10 changes: 10 additions & 0 deletions cgmanifests/submodules/cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@
"comments": "git submodule at cmake/external/mimalloc"
}
},
{
"component": {
"type": "git",
"git": {
"commitHash": "21cace4e574180ba64d9307a5e4ea9e5e94d3e8d",
"repositoryUrl": "https://github.com/boostorg/mp11.git"
},
"comments": "git submodule at cmake/external/mp11"
}
},
{
"component": {
"type": "git",
Expand Down
9 changes: 5 additions & 4 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,6 @@ set(ONNXRUNTIME_INCLUDE_DIR ${REPO_ROOT}/include/onnxruntime)

add_subdirectory(external/date EXCLUDE_FROM_ALL)

if(onnxruntime_PREFER_SYSTEM_LIB)
find_package(re2)
endif()

set(SAFEINT_INCLUDE_DIR ${REPO_ROOT}/cmake/external/SafeInt)
add_library(safeint_interface INTERFACE)
target_include_directories(safeint_interface INTERFACE ${SAFEINT_INCLUDE_DIR})
Expand All @@ -675,6 +671,11 @@ if(onnxruntime_DISABLE_EXCEPTIONS)
add_compile_definitions(optional_CONFIG_NO_EXCEPTIONS=1)
endif()

add_subdirectory(external/mp11 EXCLUDE_FROM_ALL)

if(onnxruntime_PREFER_SYSTEM_LIB)
find_package(re2)
endif()
if(NOT TARGET re2::re2)
add_subdirectory(external/re2 EXCLUDE_FROM_ALL)
set_target_properties(re2 PROPERTIES FOLDER "External/re2")
Expand Down
1 change: 1 addition & 0 deletions cmake/external/mp11
Submodule mp11 added at 21cace
2 changes: 2 additions & 0 deletions cmake/onnxruntime_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ target_include_directories(onnxruntime_common
$<TARGET_PROPERTY:safeint_interface,INTERFACE_INCLUDE_DIRECTORIES>
${OPTIONAL_LITE_INCLUDE_DIR})

target_link_libraries(onnxruntime_common Boost::mp11)

if(NOT WIN32)
target_include_directories(onnxruntime_common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/external/nsync/public")
endif()
Expand Down
1 change: 1 addition & 0 deletions cmake/onnxruntime_providers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ file(GLOB onnxruntime_cpu_featurizers_cc_srcs CONFIGURE_DEPENDS
file(GLOB onnxruntime_providers_common_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/*.h"
"${ONNXRUNTIME_ROOT}/core/providers/*.cc"
"${ONNXRUNTIME_ROOT}/core/providers/op_kernel_type_control_overrides.inc"
)

if(onnxruntime_USE_NUPHAR)
Expand Down
4 changes: 4 additions & 0 deletions cmake/winml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/p
target_include_directories(winml_lib_image PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows)
target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include)
target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/optional-lite/include)
target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/mp11/include)

# Properties
set_target_properties(winml_lib_image
Expand Down Expand Up @@ -512,6 +513,7 @@ target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/gsl
target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/SafeInt)
target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include)
target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/optional-lite/include)
target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/mp11/include)

# Properties
set_target_properties(winml_lib_api
Expand Down Expand Up @@ -594,6 +596,7 @@ target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake
target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/SafeInt)
target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include)
target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/optional-lite/include)
target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/mp11/include)

# Properties
set_target_properties(winml_lib_api_experimental
Expand Down Expand Up @@ -748,6 +751,7 @@ target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/eigen)
target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/SafeInt)
target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include)
target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/optional-lite/include)
target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/mp11/include)

# Properties
set_target_properties(winml_dll
Expand Down
2 changes: 1 addition & 1 deletion cmake/winml_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function (get_winml_test_model_src
"${winml_test_src_path}/model/*.cpp")
set(${output_winml_test_model_src} ${winml_test_model_src} PARENT_SCOPE)
set(${winml_test_model_libs} onnx_test_data_proto onnx_test_runner_common onnxruntime_common onnxruntime_mlas
onnxruntime_graph onnxruntime_test_utils onnxruntime_framework onnxruntime_flatbuffers PARENT_SCOPE)
onnxruntime_graph onnxruntime_test_utils onnxruntime_framework onnxruntime_util onnxruntime_flatbuffers PARENT_SCOPE)
endfunction()

file(GLOB winml_test_common_src CONFIGURE_DEPENDS
Expand Down
5 changes: 3 additions & 2 deletions include/onnxruntime/core/framework/data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ class NonTensorTypeBase;
class PrimitiveDataTypeBase;

// MLFloat16
union MLFloat16 {
struct MLFloat16 {
uint16_t val;

explicit MLFloat16(uint16_t x) : val(x) {}
MLFloat16() : val(0) {}
explicit MLFloat16(uint16_t x) : val(x) {}
explicit MLFloat16(float f);

// Taken from https://stackoverflow.com/a/60047308/12627730
float AsFloat(uint32_t x) const {
Expand Down
55 changes: 44 additions & 11 deletions include/onnxruntime/core/framework/data_types_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

#pragma once

#include <assert.h>
#include <stdint.h>
#include <array>
#include <cassert>
#include <cstdint>
#include <string>
#include <vector>

#include "boost/mp11.hpp"

#include "core/common/common.h"
#include "core/common/type_list.h"
#include "core/framework/data_types.h"
#include "core/graph/onnx_protobuf.h"

Expand Down Expand Up @@ -341,25 +345,54 @@ class MLTypeCallDispatcherRet {
}
};

// Version of the MLTypeDispatcher that has an input type which is passed through ('carried')
// as the first type parameter in the call to Fn when dispatching.
template <typename TCarried, template <typename, typename> class Fn, typename... Types>
class MLTypeCallDispatcherWithCarriedType {
// Version of MLTypeCallDispatcher that takes supported types as class-level template parameters.
// This enables easier use with type list representations of the supported types.
// The invocation-related template parameters like Fn move to the individual Invoke() methods.
// TODO consolidate this with the other MLTypeCallDispatcher classes
// can add additional methods to cover their usages, but need to update call sites
template <typename... Types>
Comment thread
skottmckay marked this conversation as resolved.
class MLTypeCallDispatcher2 {
static_assert(boost::mp11::mp_is_set<TypeList<Types...>>::value,
"MLTypeCallDispatcher requires a set of unique types.");

int32_t dt_type_;

public:
explicit MLTypeCallDispatcherWithCarriedType(int32_t dt_type) noexcept : dt_type_(dt_type) {}
explicit MLTypeCallDispatcher2(int32_t dt_type) noexcept : dt_type_(dt_type) {}

template <typename... Args>
template <template <typename> class Fn, typename... Args>
void Invoke(Args&&... args) const {
mltype_dispatcher_internal::CallableDispatchableHelper helper(dt_type_);
int results[] = {0, helper.template Invoke<Types>(Fn<TCarried, Types>(), std::forward<Args>(args)...)...};
ORT_UNUSED_PARAMETER(results);
ORT_ENFORCE(helper.called_ < 2, "Check for duplicate types in MLTypeCallDispatcher");

static_cast<void>(std::array<int, sizeof...(Types)>{
helper.template Invoke<Types>(Fn<Types>(), std::forward<Args>(args)...)...});

// avoid "unused parameter" warning for the case where Types is empty
static_cast<void>(std::array<int, sizeof...(Args)>{(ORT_UNUSED_PARAMETER(args), 0)...});

Comment thread
skottmckay marked this conversation as resolved.
ORT_ENFORCE(helper.called_ == 1, "Unsupported data type: ", dt_type_);
}

template <template <typename...> class Fn, typename LeadingTemplateArgTypeList, typename... Args>
void InvokeWithLeadingTemplateArgs(Args&&... args) const {
mltype_dispatcher_internal::CallableDispatchableHelper helper(dt_type_);

static_cast<void>(std::array<int, sizeof...(Types)>{
helper.template Invoke<Types>(
boost::mp11::mp_apply<Fn, boost::mp11::mp_push_back<LeadingTemplateArgTypeList, Types>>(),
std::forward<Args>(args)...)...});

// avoid "unused parameter" warning for the case where Types is empty
static_cast<void>(std::array<int, sizeof...(Args)>{(ORT_UNUSED_PARAMETER(args), 0)...});

ORT_ENFORCE(helper.called_ == 1, "Unsupported data type: ", dt_type_);
}
};

// the type MLTypeCallDispatcher2<T...> given a type list L<T...>
template <typename L>
using MLTypeCallDispatcherFromTypeList = boost::mp11::mp_apply<MLTypeCallDispatcher2, L>;

namespace data_types_internal {

enum class ContainerType : uint16_t {
Expand Down
15 changes: 15 additions & 0 deletions include/onnxruntime/core/framework/op_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <functional>

#include "boost/mp11.hpp"

#include "core/common/exceptions.h"
#include "core/common/logging/logging.h"
#include "core/common/status.h"
Expand Down Expand Up @@ -481,4 +483,17 @@ inline std::vector<MLDataType> BuildKernelDefConstraints() {
return {DataTypeImpl::GetTensorType<T>(), DataTypeImpl::GetTensorType<Types>()...};
}

// functor that calls BuildKernelDefConstraints()
template <typename... Types>
struct BuildKernelDefConstraintsFunctor {
std::vector<MLDataType> operator()() const {
return BuildKernelDefConstraints<Types...>();
}
};

// the type BuildKernelDefConstraintsFunctor<T...> given a type list L<T...>
template <typename L>
using BuildKernelDefConstraintsFunctorFromTypeList =
boost::mp11::mp_apply<BuildKernelDefConstraintsFunctor, L>;

} // namespace onnxruntime
12 changes: 12 additions & 0 deletions onnxruntime/core/common/type_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma once

namespace onnxruntime {

// this type represents a compile-time list of types
template <typename... T>
struct TypeList {};

}
4 changes: 4 additions & 0 deletions onnxruntime/core/framework/data_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "core/framework/sparse_tensor.h"
#include "core/framework/data_types_internal.h"
#include "core/graph/onnx_protobuf.h"
#include "core/util/math.h"

#ifdef __GNUC__
#pragma GCC diagnostic push
Expand All @@ -21,6 +22,9 @@
using namespace ONNX_NAMESPACE;

namespace onnxruntime {

MLFloat16::MLFloat16(float f) : val{math::floatToHalf(f)} {}

// Return the MLDataType used for a generic Tensor
template <>
MLDataType DataTypeImpl::GetType<Tensor>() {
Expand Down
Loading