Skip to content

Commit ea1d62b

Browse files
authored
Merge pull request #1077 from AlexeySachkov/private/asachkov/split-common-h-1
[NFC] Split `common.h` header [1/N]
2 parents 759adee + 5a9b53c commit ea1d62b

File tree

5 files changed

+49
-39
lines changed

5 files changed

+49
-39
lines changed

tests/common/common.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -481,45 +481,6 @@ inline bool is_linker_available(
481481
} \
482482
} while (0);
483483

484-
/// Linearizes a multi-dimensional index according to the specification.
485-
template <unsigned int dimension>
486-
size_t linearize(sycl::range<dimension> range, sycl::id<dimension> id);
487-
488-
inline size_t linearize(sycl::range<1> range, sycl::id<1> id) {
489-
static_cast<void>(range);
490-
return id[0];
491-
}
492-
493-
inline size_t linearize(sycl::range<2> range, sycl::id<2> id) {
494-
return id[1] + id[0] * range[1];
495-
}
496-
497-
inline size_t linearize(sycl::range<3> range, sycl::id<3> id) {
498-
return id[2] + id[1] * range[2] + id[0] * range[1] * range[2];
499-
}
500-
501-
/**
502-
Computes a multi-dimensional index such that id = unlinearize(range,
503-
linearize(range, id)) if id is a valid index in range. */
504-
template <unsigned int dimension>
505-
sycl::id<dimension> unlinearize(sycl::range<dimension> range, size_t id);
506-
507-
inline sycl::id<1> unlinearize(sycl::range<1>, size_t id) { return {id}; }
508-
509-
inline sycl::id<2> unlinearize(sycl::range<2> range, size_t id) {
510-
size_t id0 = id / range[1];
511-
size_t id1 = id % range[1];
512-
return {id0, id1};
513-
}
514-
515-
inline sycl::id<3> unlinearize(sycl::range<3> range, size_t id) {
516-
size_t id0 = id / (range[1] * range[2]);
517-
size_t rem = id % (range[1] * range[2]);
518-
size_t id1 = rem / range[2];
519-
size_t id2 = rem % range[2];
520-
return {id0, id1, id2};
521-
}
522-
523484
/** @brief Checks that two vectors of devices have the exact same devices,
524485
* ignoring order and repeated devices.
525486
* @param lhs std::vector with sycl::device

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*******************************************************************************/
2020

2121
#include "../../common/common.h"
22+
#include "../../common/range_index_space_id.h"
2223
#include <type_traits>
2324

2425
namespace auto_local_range::tests {

tests/group/group_api.cpp

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

2222
#include "../../util/array.h"
2323
#include "../common/common.h"
24+
#include "../common/range_index_space_id.h"
2425

2526
#include <cstddef>
2627
#include <limits>

tests/host_accessor/host_accessor_api_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +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/range_index_space_id.h"
1112
#include <cmath>
1213

1314
namespace host_accessor_api_common {

0 commit comments

Comments
 (0)