Skip to content

Commit bd56231

Browse files
author
Krzysztof Parzyszek
authored
Use std::optional instead of dmlc::optional, NFC (apache#12443)
* Use std::optional instead of dmlc::optional, NFC * Fix linter * Set deployment target to macOS 10.13 Otherwise std::optional<T>::value() is "unavailable"... * Fix linter again * Update Hexagon apps to use C++17 as the C++ standard
1 parent 09a4ac4 commit bd56231

File tree

11 files changed

+85
-106
lines changed

11 files changed

+85
-106
lines changed

apps/hexagon_api/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ExternalProject_Add(x86_tvm_runtime_rpc
4545
"-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}"
4646
"-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}"
4747
"-DUSE_HEXAGON_TOOLCHAIN=${USE_HEXAGON_TOOLCHAIN}"
48-
"-DCMAKE_CXX_STANDARD=14"
48+
"-DCMAKE_CXX_STANDARD=17"
4949
"-DUSE_LIBBACKTRACE=OFF"
5050
"-DUSE_RPC=ON"
5151
"-DUSE_CPP_RPC=ON"
@@ -79,7 +79,7 @@ ExternalProject_Add(android_tvm_runtime_rpc
7979
"-DANDROID_ABI=${ANDROID_ABI}"
8080
"-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}"
8181
"-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}"
82-
"-DCMAKE_CXX_STANDARD=14"
82+
"-DCMAKE_CXX_STANDARD=17"
8383
"-DUSE_LIBBACKTRACE=OFF"
8484
"-DUSE_RPC=ON"
8585
"-DUSE_CPP_RPC=ON"
@@ -123,6 +123,7 @@ ExternalProject_Add(hexagon_tvm_runtime_rpc
123123
"-DCMAKE_CXX_COMPILER=${USE_HEXAGON_TOOLCHAIN}/bin/hexagon-clang++"
124124
"-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}"
125125
"-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}"
126+
"-DCMAKE_CXX_STANDARD=17"
126127
"-DUSE_LIBBACKTRACE=OFF"
127128
"-DUSE_RPC=OFF"
128129
"-DUSE_HEXAGON=ON"

apps/hexagon_launcher/cmake/android/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ExternalProject_Add(android_tvm_runtime
7373
CMAKE_ARGS
7474
"-DANDROID_ABI=${ANDROID_ABI}"
7575
"-DANDROID_PLATFORM=${ANDROID_PLATFORM}"
76-
"-DCMAKE_CXX_STANDARD=14"
76+
"-DCMAKE_CXX_STANDARD=17"
7777
"-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
7878
"-DUSE_HEXAGON=ON"
7979
"-DUSE_GRAPH_EXECUTOR=OFF"

apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ExternalProject_Add(static_hexagon_tvm_runtime
8282
"-DBUILD_STATIC_RUNTIME=ON"
8383
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
8484
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
85-
"-DCMAKE_CXX_STANDARD=14"
85+
"-DCMAKE_CXX_STANDARD=17"
8686
"-DUSE_HEXAGON=ON"
8787
"-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}"
8888
"-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}"

conda/recipe/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ MACOS_OPT=""
2626
if [ "$target_platform" == "osx-64" ]; then
2727
# macOS 64 bits
2828
GPU_OPT="-DUSE_METAL=ON"
29-
MACOS_OPT="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.12"
29+
MACOS_OPT="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13"
3030
elif [ "$target_platform" == "linux-64" ]; then
3131
TOOLCHAIN_OPT="-DCMAKE_TOOLCHAIN_FILE=${RECIPE_DIR}/cross-linux.cmake"
3232
fi

src/relay/transforms/fold_explicit_padding.cc

+8-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* \brief A pass for folding explicit pads into other ops.
2323
*/
2424

25-
#include <dmlc/optional.h>
2625
#include <tvm/relay/dataflow_matcher.h>
2726
#include <tvm/relay/expr.h>
2827
#include <tvm/relay/expr_functor.h>
@@ -32,6 +31,10 @@
3231
#include <tvm/tir/op.h>
3332
#include <tvm/topi/nn/pooling.h>
3433

34+
#include <optional>
35+
#include <set>
36+
#include <string>
37+
3538
#include "../op/tensor/transform.h"
3639
#include "pattern_utils.h"
3740

@@ -180,10 +183,10 @@ class SimplifyExplicitPad {
180183
return attrs;
181184
}
182185

183-
static const Optional<Array<PrimExpr>> get_padding(const PadAttrs* param,
184-
std::string data_layout) {
186+
static const std::optional<Array<PrimExpr>> get_padding(const PadAttrs* param,
187+
std::string data_layout) {
185188
// Gets spatial axes padding from the given PadAttrs `param`. If padding
186-
// is non-zero on non-spatial axes, return NullOpt.
189+
// is non-zero on non-spatial axes, return std::nullopt.
187190
ICHECK(param);
188191
ICHECK(data_layout.size() == param->pad_width.size())
189192
<< "Data Layout and padding attributes should have the same extent";
@@ -196,7 +199,7 @@ class SimplifyExplicitPad {
196199
if (!image_dims.count(data_layout[i])) {
197200
for (size_t j = 0; j < param->pad_width[i].size(); ++j) {
198201
if (param->pad_width[i][j] != 0) {
199-
return NullOpt;
202+
return std::nullopt;
200203
}
201204
}
202205
}

src/relay/transforms/pattern_utils.h

+17-18
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#define TVM_RELAY_TRANSFORMS_PATTERN_UTILS_H_
2828

2929
#include <builtin_fp16.h>
30-
#include <dmlc/optional.h>
3130
#include <tvm/node/structural_equal.h>
3231
#include <tvm/relay/analysis.h>
3332
#include <tvm/relay/attrs/nn.h>
@@ -40,6 +39,7 @@
4039
#include <tvm/tir/data_layout.h>
4140

4241
#include <limits>
42+
#include <optional>
4343
#include <string>
4444
#include <utility>
4545
#include <vector>
@@ -405,48 +405,47 @@ inline bool IsEqualScalar(const Expr& a, const Expr& b) {
405405
* \param i element index
406406
* \return Converted scalar value, or None if conversion failed
407407
*/
408-
static inline dmlc::optional<long double> TryToScalar(const runtime::NDArray& array, size_t i = 0) {
408+
static inline std::optional<long double> TryToScalar(const runtime::NDArray& array, size_t i = 0) {
409409
if (array->dtype.code == kDLInt) {
410410
if (array->dtype.bits == 8) {
411-
return dmlc::optional<long double>(reinterpret_cast<int8_t*>(array->data)[i]);
411+
return std::optional<long double>(reinterpret_cast<int8_t*>(array->data)[i]);
412412
} else if (array->dtype.bits == 16) {
413-
return dmlc::optional<long double>(reinterpret_cast<int16_t*>(array->data)[i]);
413+
return std::optional<long double>(reinterpret_cast<int16_t*>(array->data)[i]);
414414
} else if (array->dtype.bits == 32) {
415-
return dmlc::optional<long double>(reinterpret_cast<int32_t*>(array->data)[i]);
415+
return std::optional<long double>(reinterpret_cast<int32_t*>(array->data)[i]);
416416
} else if (array->dtype.bits == 64) {
417-
return dmlc::optional<long double>(reinterpret_cast<int64_t*>(array->data)[i]);
417+
return std::optional<long double>(reinterpret_cast<int64_t*>(array->data)[i]);
418418
}
419419
} else if (array->dtype.code == kDLUInt) {
420420
if (array->dtype.bits == 1) { // bool
421-
return dmlc::optional<long double>(reinterpret_cast<uint8_t*>(array->data)[i]);
421+
return std::optional<long double>(reinterpret_cast<uint8_t*>(array->data)[i]);
422422
} else if (array->dtype.bits == 8) {
423-
return dmlc::optional<long double>(reinterpret_cast<uint8_t*>(array->data)[i]);
423+
return std::optional<long double>(reinterpret_cast<uint8_t*>(array->data)[i]);
424424
} else if (array->dtype.bits == 16) {
425-
return dmlc::optional<long double>(reinterpret_cast<uint16_t*>(array->data)[i]);
425+
return std::optional<long double>(reinterpret_cast<uint16_t*>(array->data)[i]);
426426
} else if (array->dtype.bits == 32) {
427-
return dmlc::optional<long double>(reinterpret_cast<uint32_t*>(array->data)[i]);
427+
return std::optional<long double>(reinterpret_cast<uint32_t*>(array->data)[i]);
428428
} else if (array->dtype.bits == 64) {
429-
return dmlc::optional<long double>(reinterpret_cast<uint64_t*>(array->data)[i]);
429+
return std::optional<long double>(reinterpret_cast<uint64_t*>(array->data)[i]);
430430
}
431431
} else if (array->dtype.code == kDLFloat) {
432432
if (array->dtype.bits == 16) {
433-
return dmlc::optional<long double>(
433+
return std::optional<long double>(
434434
__extendXfYf2__<uint16_t, uint16_t, 10, float, uint32_t, 23>(
435435
reinterpret_cast<uint16_t*>(array->data)[i]));
436436
}
437437
if (array->dtype.bits == 32) {
438-
return dmlc::optional<long double>(reinterpret_cast<float*>(array->data)[i]);
438+
return std::optional<long double>(reinterpret_cast<float*>(array->data)[i]);
439439
} else if (array->dtype.bits == 64) {
440-
return dmlc::optional<long double>(reinterpret_cast<double*>(array->data)[i]);
440+
return std::optional<long double>(reinterpret_cast<double*>(array->data)[i]);
441441
}
442442
} else if (array->dtype.code == kDLBfloat) {
443443
if (array->dtype.bits == 16) {
444-
return dmlc::optional<long double>(
445-
__extendXfYf2__<uint16_t, uint16_t, 7, float, uint32_t, 23>(
446-
reinterpret_cast<uint16_t*>(array->data)[i]));
444+
return std::optional<long double>(__extendXfYf2__<uint16_t, uint16_t, 7, float, uint32_t, 23>(
445+
reinterpret_cast<uint16_t*>(array->data)[i]));
447446
}
448447
}
449-
return dmlc::optional<long double>();
448+
return std::nullopt;
450449
}
451450

452451
/*!

0 commit comments

Comments
 (0)