Skip to content

Use c++17 for size test #5178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions extension/llm/custom_ops/op_sdpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static inline scalar_t* conditional_data_ptr(scalar_t* ptr, scalar_t* ptr2) {
template <
typename scalar_t,
typename std::enable_if_t<
::executorch::runtime::is_reduced_floating_point<scalar_t>::value,
::executorch::runtime::is_reduced_floating_point_v<scalar_t>,
int> = 0>
static inline scalar_t* conditional_data_ptr(float* ptr, scalar_t* ptr2) {
(void)ptr;
Expand Down Expand Up @@ -247,7 +247,7 @@ void cpu_flash_attention(
"KV_split_size must be greater than q_split_size");

constexpr bool is_reduced_type =
::executorch::runtime::is_reduced_floating_point<scalar_t>::value;
::executorch::runtime::is_reduced_floating_point_v<scalar_t>;

ET_CHECK_MSG(
!is_reduced_type, "FlashAttention does not support reduced types.");
Expand Down
4 changes: 4 additions & 0 deletions runtime/core/exec_aten/util/scalar_type_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ struct is_reduced_floating_point
bool,
std::is_same<T, torch::executor::Half>::value ||
std::is_same<T, torch::executor::BFloat16>::value> {};

template <typename T>
constexpr bool is_reduced_floating_point_v =
is_reduced_floating_point<T>::value;
#endif

/// Maps ScalarTypes to C++ types.
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/portable_type/half.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct alignas(2) Half {
namespace internal {

inline float fp32_from_bits(uint32_t w) {
static_assert(sizeof(float) == sizeof(uint32_t), "");
static_assert(sizeof(float) == sizeof(uint32_t));
union {
uint32_t as_bits;
float as_value;
Expand All @@ -71,7 +71,7 @@ inline float fp32_from_bits(uint32_t w) {
}

inline uint32_t fp32_to_bits(float f) {
static_assert(sizeof(float) == sizeof(uint32_t), "");
static_assert(sizeof(float) == sizeof(uint32_t));
union {
float as_value;
uint32_t as_bits;
Expand Down
21 changes: 7 additions & 14 deletions runtime/core/portable_type/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ class basic_string_view final {
}

constexpr const_reference at(size_type pos) const {
return (pos >= size_)
? (ET_ASSERT_MESSAGE_EMIT(
" (%s): "
"string_view::operator[] or string_view::at() out of range",
pos >= size_),
torch::executor::runtime_abort())
: at_(pos);
ET_CHECK_MSG(
pos >= size_,
"string_view::operator[] or string_view::at() out of range");
return at_(pos);
}

constexpr const_reference front() const {
Expand Down Expand Up @@ -140,13 +137,9 @@ class basic_string_view final {

constexpr basic_string_view substr(size_type pos = 0, size_type count = npos)
const {
return (pos > size_)
? (ET_ASSERT_MESSAGE_EMIT(
" (%s): "
"basic_string_view::substr parameter out of bounds.",
pos > size_),
torch::executor::runtime_abort())
: substr_(pos, count);
ET_CHECK_MSG(
pos > size_, "basic_string_view::substr parameter out of bounds.");
return substr_(pos, count);
}

constexpr int compare(basic_string_view rhs) const noexcept {
Expand Down
3 changes: 1 addition & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
cmake_minimum_required(VERSION 3.19)
project(size_test)

# Use C++11 for size test.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)

Expand Down
17 changes: 0 additions & 17 deletions test/build_size_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,12 @@ set -e
# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")/../.ci/scripts/utils.sh"

# Set compile flags for Clang and GCC.
# -Wno-gnu allows us to use gnu statement-expressions.
# -Werror -Wc++17* ensure we do not use features from C++17.
CXX_FLAGS="-Wno-gnu"
compiler=$(cc --version)
if [[ $compiler == *"clang"* ]]; then
CXX_FLAGS="$CXX_FLAGS -Werror -Wc++17-extensions -Wc++14-extensions"
elif [[ $compiler == *"cc"* ]]; then
CXX_FLAGS="$CXX_FLAGS -Werror -Wc++17-compat -Wc++14-compat"
else
echo "Unknown compiler: $compiler"
exit 1
fi
echo "Using compiler $compiler with flags $CXX_FLAGS"

cmake_install_executorch_lib() {
echo "Installing libexecutorch.a"
rm -rf cmake-out

retry cmake -DBUCK2="$BUCK2" \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
-DCMAKE_INSTALL_PREFIX=cmake-out \
-DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
Expand Down
Loading