Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
Use std::optional instead of dmlc::optional, NFC (apache#12443)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Krzysztof Parzyszek authored and xinetzone committed Nov 25, 2022
1 parent 6525394 commit d765d24
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 106 deletions.
5 changes: 3 additions & 2 deletions apps/hexagon_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ExternalProject_Add(x86_tvm_runtime_rpc
"-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}"
"-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}"
"-DUSE_HEXAGON_TOOLCHAIN=${USE_HEXAGON_TOOLCHAIN}"
"-DCMAKE_CXX_STANDARD=14"
"-DCMAKE_CXX_STANDARD=17"
"-DUSE_LIBBACKTRACE=OFF"
"-DUSE_RPC=ON"
"-DUSE_CPP_RPC=ON"
Expand Down Expand Up @@ -79,7 +79,7 @@ ExternalProject_Add(android_tvm_runtime_rpc
"-DANDROID_ABI=${ANDROID_ABI}"
"-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}"
"-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}"
"-DCMAKE_CXX_STANDARD=14"
"-DCMAKE_CXX_STANDARD=17"
"-DUSE_LIBBACKTRACE=OFF"
"-DUSE_RPC=ON"
"-DUSE_CPP_RPC=ON"
Expand Down Expand Up @@ -123,6 +123,7 @@ ExternalProject_Add(hexagon_tvm_runtime_rpc
"-DCMAKE_CXX_COMPILER=${USE_HEXAGON_TOOLCHAIN}/bin/hexagon-clang++"
"-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}"
"-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}"
"-DCMAKE_CXX_STANDARD=17"
"-DUSE_LIBBACKTRACE=OFF"
"-DUSE_RPC=OFF"
"-DUSE_HEXAGON=ON"
Expand Down
2 changes: 1 addition & 1 deletion apps/hexagon_launcher/cmake/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ExternalProject_Add(android_tvm_runtime
CMAKE_ARGS
"-DANDROID_ABI=${ANDROID_ABI}"
"-DANDROID_PLATFORM=${ANDROID_PLATFORM}"
"-DCMAKE_CXX_STANDARD=14"
"-DCMAKE_CXX_STANDARD=17"
"-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
"-DUSE_HEXAGON=ON"
"-DUSE_GRAPH_EXECUTOR=OFF"
Expand Down
2 changes: 1 addition & 1 deletion apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ExternalProject_Add(static_hexagon_tvm_runtime
"-DBUILD_STATIC_RUNTIME=ON"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_CXX_STANDARD=14"
"-DCMAKE_CXX_STANDARD=17"
"-DUSE_HEXAGON=ON"
"-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}"
"-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}"
Expand Down
2 changes: 1 addition & 1 deletion conda/recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MACOS_OPT=""
if [ "$target_platform" == "osx-64" ]; then
# macOS 64 bits
GPU_OPT="-DUSE_METAL=ON"
MACOS_OPT="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.12"
MACOS_OPT="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13"
elif [ "$target_platform" == "linux-64" ]; then
TOOLCHAIN_OPT="-DCMAKE_TOOLCHAIN_FILE=${RECIPE_DIR}/cross-linux.cmake"
fi
Expand Down
13 changes: 8 additions & 5 deletions src/relay/transforms/fold_explicit_padding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* \brief A pass for folding explicit pads into other ops.
*/

#include <dmlc/optional.h>
#include <tvm/relay/dataflow_matcher.h>
#include <tvm/relay/expr.h>
#include <tvm/relay/expr_functor.h>
Expand All @@ -32,6 +31,10 @@
#include <tvm/tir/op.h>
#include <tvm/topi/nn/pooling.h>

#include <optional>
#include <set>
#include <string>

#include "../op/tensor/transform.h"
#include "pattern_utils.h"

Expand Down Expand Up @@ -180,10 +183,10 @@ class SimplifyExplicitPad {
return attrs;
}

static const Optional<Array<PrimExpr>> get_padding(const PadAttrs* param,
std::string data_layout) {
static const std::optional<Array<PrimExpr>> get_padding(const PadAttrs* param,
std::string data_layout) {
// Gets spatial axes padding from the given PadAttrs `param`. If padding
// is non-zero on non-spatial axes, return NullOpt.
// is non-zero on non-spatial axes, return std::nullopt.
ICHECK(param);
ICHECK(data_layout.size() == param->pad_width.size())
<< "Data Layout and padding attributes should have the same extent";
Expand All @@ -196,7 +199,7 @@ class SimplifyExplicitPad {
if (!image_dims.count(data_layout[i])) {
for (size_t j = 0; j < param->pad_width[i].size(); ++j) {
if (param->pad_width[i][j] != 0) {
return NullOpt;
return std::nullopt;
}
}
}
Expand Down
35 changes: 17 additions & 18 deletions src/relay/transforms/pattern_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#define TVM_RELAY_TRANSFORMS_PATTERN_UTILS_H_

#include <builtin_fp16.h>
#include <dmlc/optional.h>
#include <tvm/node/structural_equal.h>
#include <tvm/relay/analysis.h>
#include <tvm/relay/attrs/nn.h>
Expand All @@ -40,6 +39,7 @@
#include <tvm/tir/data_layout.h>

#include <limits>
#include <optional>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -405,48 +405,47 @@ inline bool IsEqualScalar(const Expr& a, const Expr& b) {
* \param i element index
* \return Converted scalar value, or None if conversion failed
*/
static inline dmlc::optional<long double> TryToScalar(const runtime::NDArray& array, size_t i = 0) {
static inline std::optional<long double> TryToScalar(const runtime::NDArray& array, size_t i = 0) {
if (array->dtype.code == kDLInt) {
if (array->dtype.bits == 8) {
return dmlc::optional<long double>(reinterpret_cast<int8_t*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<int8_t*>(array->data)[i]);
} else if (array->dtype.bits == 16) {
return dmlc::optional<long double>(reinterpret_cast<int16_t*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<int16_t*>(array->data)[i]);
} else if (array->dtype.bits == 32) {
return dmlc::optional<long double>(reinterpret_cast<int32_t*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<int32_t*>(array->data)[i]);
} else if (array->dtype.bits == 64) {
return dmlc::optional<long double>(reinterpret_cast<int64_t*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<int64_t*>(array->data)[i]);
}
} else if (array->dtype.code == kDLUInt) {
if (array->dtype.bits == 1) { // bool
return dmlc::optional<long double>(reinterpret_cast<uint8_t*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<uint8_t*>(array->data)[i]);
} else if (array->dtype.bits == 8) {
return dmlc::optional<long double>(reinterpret_cast<uint8_t*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<uint8_t*>(array->data)[i]);
} else if (array->dtype.bits == 16) {
return dmlc::optional<long double>(reinterpret_cast<uint16_t*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<uint16_t*>(array->data)[i]);
} else if (array->dtype.bits == 32) {
return dmlc::optional<long double>(reinterpret_cast<uint32_t*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<uint32_t*>(array->data)[i]);
} else if (array->dtype.bits == 64) {
return dmlc::optional<long double>(reinterpret_cast<uint64_t*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<uint64_t*>(array->data)[i]);
}
} else if (array->dtype.code == kDLFloat) {
if (array->dtype.bits == 16) {
return dmlc::optional<long double>(
return std::optional<long double>(
__extendXfYf2__<uint16_t, uint16_t, 10, float, uint32_t, 23>(
reinterpret_cast<uint16_t*>(array->data)[i]));
}
if (array->dtype.bits == 32) {
return dmlc::optional<long double>(reinterpret_cast<float*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<float*>(array->data)[i]);
} else if (array->dtype.bits == 64) {
return dmlc::optional<long double>(reinterpret_cast<double*>(array->data)[i]);
return std::optional<long double>(reinterpret_cast<double*>(array->data)[i]);
}
} else if (array->dtype.code == kDLBfloat) {
if (array->dtype.bits == 16) {
return dmlc::optional<long double>(
__extendXfYf2__<uint16_t, uint16_t, 7, float, uint32_t, 23>(
reinterpret_cast<uint16_t*>(array->data)[i]));
return std::optional<long double>(__extendXfYf2__<uint16_t, uint16_t, 7, float, uint32_t, 23>(
reinterpret_cast<uint16_t*>(array->data)[i]));
}
}
return dmlc::optional<long double>();
return std::nullopt;
}

/*!
Expand Down
Loading

0 comments on commit d765d24

Please sign in to comment.