Skip to content

Commit

Permalink
Merge pull request #828 from AlexeySachkov/private/asachkov/drop-lega…
Browse files Browse the repository at this point in the history
…cy-getset-element

[NFC] Drop legacy get/setElement helpers
  • Loading branch information
bader authored Nov 6, 2023
2 parents 5febc56 + 0e69b77 commit 9092945
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 325 deletions.
4 changes: 2 additions & 2 deletions tests/accessor_legacy/accessor_api_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ template <typename T1, int N>
bool check_elems_equal(const sycl::vec<T1, N>& actual,
const sycl::vec<T1, N>& expected) {
for (int i = 0; i < N; i++) {
if (!check_elems_equal(getElement(actual, i), getElement(expected, i))) {
if (!check_elems_equal(actual[i], expected[i])) {
return false;
}
}
Expand All @@ -691,7 +691,7 @@ bool check_elems_equal(const sycl::vec<T1, N>& actual,
template <typename T1, int N>
bool check_elems_equal(const sycl::vec<T1, N>& actual, const T1& expected) {
for (int i = 0; i < N; i++) {
if (!check_elems_equal(getElement(actual, i), expected)) {
if (!check_elems_equal(actual[i], expected)) {
return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <catch2/catch_test_macros.hpp>

#include "../../util/conversion.h"
#include "../../util/math_vector.h"
#include "../../util/proxy.h"
#include "../../util/sycl_enums.h"
#include "../../util/test_base.h"
Expand Down
32 changes: 13 additions & 19 deletions tests/common/common_vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "../../util/accuracy.h"
#include "../../util/math_reference.h"
#include "../../util/math_vector.h"
#include "../../util/proxy.h"
#include "../../util/test_base.h"
#include "../../util/type_traits.h"
Expand Down Expand Up @@ -61,7 +60,7 @@ template <typename vecType, int numOfElems>
bool check_vector_values(sycl::vec<vecType, numOfElems> vector,
vecType* vals) {
for (int i = 0; i < numOfElems; i++) {
if ((vals[i] != getElement(vector, i))) {
if ((vals[i] != vector[i])) {
return false;
}
}
Expand All @@ -77,7 +76,7 @@ typename std::enable_if<is_sycl_floating_point<vecType>::value, bool>::type
check_vector_values_div(sycl::vec<vecType, numOfElems> vector,
vecType *vals) {
for (int i = 0; i < numOfElems; i++) {
vecType vectorValue = getElement(vector, i);
vecType vectorValue = vector[i];
if (vals[i] == vectorValue)
continue;
const vecType ulpsExpected = 2.5; // Min Accuracy for x / y
Expand Down Expand Up @@ -115,7 +114,7 @@ bool check_single_vector_op(vectorType vector1, lambdaFunc lambda) {
return false;
}
for (int i = 0; i < vecSize; i++) {
if (getElement(vector1, i) != getElement(vector2, i)) {
if (vector1[i] != vector2[i]) {
return false;
}
}
Expand All @@ -130,8 +129,7 @@ template <typename vecType, int N, typename convertType>
sycl::vec<convertType, N> convert_vec(sycl::vec<vecType, N> inputVec) {
sycl::vec<convertType, N> resVec;
for (size_t i = 0; i < N; ++i) {
vecType elem = getElement(inputVec, i);
setElement<convertType, N>(resVec, i, convertType(elem));
resVec[i] = convertType(inputVec[i]);
}
return resVec;
}
Expand All @@ -143,8 +141,7 @@ sycl::vec<convertType, N> rte(sycl::vec<vecType, N> inputVec) {
sycl::vec<vecType, N> roundedVec = reference::rint(inputVec);
sycl::vec<convertType, N> resVec;
for (size_t i = 0; i < N; ++i) {
vecType elem = getElement(roundedVec, i);
setElement<convertType, N>(resVec, i, static_cast<convertType>(elem));
resVec[i] = static_cast<convertType>(roundedVec[i]);
}
return resVec;
}
Expand All @@ -158,8 +155,7 @@ sycl::vec<convertType, N> rtz(sycl::vec<vecType, N> inputVec) {
sycl::vec<vecType, N> roundedVec = reference::trunc(inputVec);
sycl::vec<convertType, N> resVec;
for (size_t i = 0; i < N; ++i) {
vecType elem = getElement(roundedVec, i);
setElement<convertType, N>(resVec, i, static_cast<convertType>(elem));
resVec[i] = static_cast<convertType>(roundedVec[i]);
}
return resVec;
}
Expand All @@ -173,8 +169,7 @@ sycl::vec<convertType, N> rtp(sycl::vec<vecType, N> inputVec) {
sycl::vec<vecType, N> roundedVec = reference::ceil(inputVec);
sycl::vec<convertType, N> resVec;
for (size_t i = 0; i < N; ++i) {
vecType elem = getElement(roundedVec, i);
setElement<convertType, N>(resVec, i, static_cast<convertType>(elem));
resVec[i] = static_cast<convertType>(roundedVec[i]);
}
return resVec;
}
Expand All @@ -188,8 +183,7 @@ sycl::vec<convertType, N> rtn(sycl::vec<vecType, N> inputVec) {
sycl::vec<vecType, N> roundedVec = reference::floor(inputVec);
sycl::vec<convertType, N> resVec;
for (size_t i = 0; i < N; ++i) {
vecType elem = getElement(roundedVec, i);
setElement<convertType, N>(resVec, i, static_cast<convertType>(elem));
resVec[i] = static_cast<convertType>(roundedVec[i]);
}
return resVec;
}
Expand All @@ -205,8 +199,8 @@ void handleFPToUnsignedConv(sycl::vec<vecType, N>& inputVec) {
if constexpr (is_sycl_floating_point<vecType>::value &&
std::is_unsigned_v<convertType>) {
for (size_t i = 0; i < N; ++i) {
vecType elem = getElement(inputVec, i);
if (elem < 0) setElement<vecType, N>(inputVec, i, -elem);
vecType elem = inputVec[i];
if (elem < 0) inputVec[i] = -elem;
}
}
}
Expand Down Expand Up @@ -383,15 +377,15 @@ bool check_as_result(sycl::vec<vecType, N> inputVec,
sycl::vec<asType, asN> asVec) {
vecType tmp_ptr[N];
for (size_t i = 0; i < N; ++i) {
tmp_ptr[i] = getElement(inputVec, i);
tmp_ptr[i] = inputVec[i];
}
asType exp_ptr[asN];
for (size_t i = 0; i < asN; ++i) {
exp_ptr[i] = getElement(asVec, i);
exp_ptr[i] = asVec[i];
}
std::memcpy(exp_ptr, tmp_ptr, std::min(sizeof(exp_ptr), sizeof(tmp_ptr)));
for (size_t i = 0; i < asN; ++i) {
if (exp_ptr[i] != getElement(asVec, i)) {
if (exp_ptr[i] != asVec[i]) {
return false;
}
}
Expand Down
6 changes: 2 additions & 4 deletions tests/hierarchical/hierarchical_non_uniform_local_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*******************************************************************************/

#include "../common/common.h"
#include "../../util/math_vector.h"

#define TEST_NAME hierarchical_non_uniform_local_range

Expand All @@ -41,12 +40,11 @@ using namespace sycl_cts;
void check_expected(const std::vector<sycl::int3> &data, unsigned local_id,
unsigned idx, int dim, bool set, util::logger &log) {
int expected = set ? local_id : -1;
if (getElement(data[idx], dim - 1) != expected) {
if (data[idx][dim - 1] != expected) {
std::string errorMessage =
std::string("Value for global id ") + std::to_string(idx) +
std::string(" for dim = ") + std::to_string(dim) +
std::string(" was not correct (") +
std::to_string(getElement(data[idx], dim - 1)) +
std::string(" was not correct (") + std::to_string(data[idx][dim - 1]) +
std::string(" instead of ") + std::to_string(expected) + ")";
FAIL(log, errorMessage);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/math_builtin_api/math_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool verify(sycl_cts::util::logger& log, sycl::vec<T, N> a,
sycl::vec<T, N> b = r.res;
for (int i = 0; i < sycl_cts::math::numElements(a); i++)
if (r.undefined.find(i) == r.undefined.end() &&
!verify(log, getElement(a, i), getElement(b, i), accuracy, comment))
!verify(log, a[i], b[i], accuracy, comment))
return false;
return true;
}
Expand Down
5 changes: 2 additions & 3 deletions util/math_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "../util/stl.h"
#include "./../oclmath/mt19937.h"
#include "./math_vector.h"

namespace sycl_cts {
/** math utility functions
Expand Down Expand Up @@ -92,7 +91,7 @@ T getElement(const T &f, int) {
* extract an individual element. */
template <typename T, int dim>
T getElement(sycl::vec<T, dim> &f, int ix) {
return getComponent<T, dim>()(f, ix);
return f[ix];
}

// FIXME: hipSYCL does not support marray
Expand All @@ -107,7 +106,7 @@ T getElement(sycl::marray<T, dim> &f, size_t ix) {

template <typename T, int dim>
void setElement(sycl::vec<T, dim> &f, int ix, T value) {
setComponent<T, dim>()(f, ix, value);
f[ix] = value;
}

template <typename R, typename T, int N, typename funT, typename... Args>
Expand Down
3 changes: 2 additions & 1 deletion util/math_reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ sycl::vec<T, N> cross_t(sycl::vec<T, N> a, sycl::vec<T, N> b) {
temp_res[1] = av[2] * bv[0] - av[0] * bv[2];
temp_res[2] = av[0] * bv[1] - av[1] * bv[0];
temp_res[3] = 0.0;
for (int i = 0; i < N; i++) setElement<T, N>(res, i, temp_res[i]);
for (int i = 0; i < N; i++) res[i] = temp_res[i];

return res;
}

Expand Down
Loading

0 comments on commit 9092945

Please sign in to comment.