Skip to content

[SYCL][ESIMD] Fix compile-time evaluated functions, add test. #2161

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
Jul 23, 2020
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 sycl/include/CL/sycl/intel/esimd/detail/esimd_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ template <unsigned int N, unsigned int K> struct NextPowerOf2<N, K, false> {
}
};

template <unsigned int N> unsigned int getNextPowerOf2() {
template <unsigned int N> constexpr unsigned int getNextPowerOf2() {
return NextPowerOf2<N, 1, (1 >= N)>::get();
}

template <> unsigned int getNextPowerOf2<0>() { return 0; }
template <> constexpr unsigned int getNextPowerOf2<0>() { return 0; }

/// Compute binary logarithm of a constexpr with guaranteed compile-time
/// evaluation.
Expand Down
15 changes: 15 additions & 0 deletions sycl/test/regression/esimd-util-compiler-eval.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clangxx -fsycl -fsycl-explicit-simd -fsycl-device-only -c %s
// This test checks compile-time evaluation of functions from esimd_util.hpp

#include "CL/sycl.hpp"
#include "CL/sycl/intel/esimd/esimd.hpp"

static_assert(__esimd::getNextPowerOf2<0>() == 0, "");
static_assert(__esimd::getNextPowerOf2<1>() == 1, "");
static_assert(__esimd::getNextPowerOf2<7>() == 8, "");
static_assert(__esimd::getNextPowerOf2<1024>() == 1024, "");

static_assert(__esimd::log2<0>() == 0, "");
static_assert(__esimd::log2<1>() == 0, "");
static_assert(__esimd::log2<7>() == 2, "");
static_assert(__esimd::log2<1024 * 1024>() == 20, "");