Skip to content

Commit 5a9b53c

Browse files
committed
Apply comments
1 parent 906ee9b commit 5a9b53c

File tree

5 files changed

+49
-68
lines changed

5 files changed

+49
-68
lines changed

tests/common/index_space.h

Lines changed: 0 additions & 65 deletions
This file was deleted.

tests/common/range_index_space_id.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
//
2020
*******************************************************************************/
2121

22+
#ifndef __SYCLCTS_TESTS_COMMON_RANGE_INDEX_SPACE_ID_H
23+
#define __SYCLCTS_TESTS_COMMON_RANGE_INDEX_SPACE_ID_H
24+
2225
#ifndef SYCL_CTS_COMPILING_WITH_ADAPTIVECPP
2326
#include "../common/type_coverage.h"
2427
#endif
2528

29+
#include "once_per_unit.h"
30+
2631
namespace range_index_space_id {
2732

2833
enum class check_codes : size_t {
@@ -95,3 +100,44 @@ void check_members_test(const std::string& type_name) {
95100
}
96101

97102
} // namespace range_index_space_id
103+
104+
/// Linearizes a multi-dimensional index according to the specification.
105+
template <unsigned int dimension>
106+
size_t linearize(sycl::range<dimension> range, sycl::id<dimension> id);
107+
108+
inline size_t linearize(sycl::range<1> range, sycl::id<1> id) {
109+
static_cast<void>(range);
110+
return id[0];
111+
}
112+
113+
inline size_t linearize(sycl::range<2> range, sycl::id<2> id) {
114+
return id[1] + id[0] * range[1];
115+
}
116+
117+
inline size_t linearize(sycl::range<3> range, sycl::id<3> id) {
118+
return id[2] + id[1] * range[2] + id[0] * range[1] * range[2];
119+
}
120+
121+
/**
122+
Computes a multi-dimensional index such that id = unlinearize(range,
123+
linearize(range, id)) if id is a valid index in range. */
124+
template <unsigned int dimension>
125+
sycl::id<dimension> unlinearize(sycl::range<dimension> range, size_t id);
126+
127+
inline sycl::id<1> unlinearize(sycl::range<1>, size_t id) { return {id}; }
128+
129+
inline sycl::id<2> unlinearize(sycl::range<2> range, size_t id) {
130+
size_t id0 = id / range[1];
131+
size_t id1 = id % range[1];
132+
return {id0, id1};
133+
}
134+
135+
inline sycl::id<3> unlinearize(sycl::range<3> range, size_t id) {
136+
size_t id0 = id / (range[1] * range[2]);
137+
size_t rem = id % (range[1] * range[2]);
138+
size_t id1 = rem / range[2];
139+
size_t id2 = rem % range[2];
140+
return {id0, id1, id2};
141+
}
142+
143+
#endif // __SYCLCTS_TESTS_COMMON_RANGE_INDEX_SPACE_ID_H

tests/extension/oneapi_auto_local_range/auto_local_range.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*******************************************************************************/
2020

2121
#include "../../common/common.h"
22-
#include "../../common/index_space.h"
22+
#include "../../common/range_index_space_id.h"
2323
#include <type_traits>
2424

2525
namespace auto_local_range::tests {

tests/group/group_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "../../util/array.h"
2323
#include "../common/common.h"
24-
#include "../common/index_space.h"
24+
#include "../common/range_index_space_id.h"
2525

2626
#include <cstddef>
2727
#include <limits>

tests/host_accessor/host_accessor_api_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef SYCL_CTS_HOST_ACCESSOR_API_COMMON_H
99
#define SYCL_CTS_HOST_ACCESSOR_API_COMMON_H
1010
#include "../accessor_basic/accessor_common.h"
11-
#include "../common/index_space.h"
11+
#include "../common/range_index_space_id.h"
1212
#include <cmath>
1313

1414
namespace host_accessor_api_common {

0 commit comments

Comments
 (0)