Skip to content

Commit 52a340b

Browse files
committed
Test and fix
1 parent 3c78ef1 commit 52a340b

File tree

5 files changed

+44
-38
lines changed

5 files changed

+44
-38
lines changed

algorithms/cudahip/ArrayManip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ template void
8080

8181
//--------------------------------------------------------------------------------------------------
8282
__global__ void kernel_touchMemory(void* ptr, size_t size, bool clean) {
83-
int id = threadIdx.x + blockIdx.x * blockDim.x;
83+
const int id = threadIdx.x + blockIdx.x * blockDim.x;
8484
if (clean) {
8585
imemset(ptr, size, id, blockDim.x * gridDim.x);
8686
} else {

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ add_subdirectory(.. root)
2222

2323
find_package(GTest REQUIRED)
2424

25-
add_executable(tests main.cpp reductions.cpp array_manip.cpp memory.cpp batch_manip.cpp)
25+
add_executable(tests main.cpp reductions.cpp memory.cpp array_manip.cpp batch_manip.cpp)
2626
target_link_libraries(tests PRIVATE device ${GTEST_BOTH_LIBRARIES})
2727
target_include_directories(tests PRIVATE ${GTEST_INCLUDE_DIR})
2828

tests/array_manip.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@ TEST_F(ArrayManip, touchNoClean32) {
7373
device->api->freeGlobMem(arr);
7474
}
7575

76+
// avoid double, due to some archs (also in the CI) don't seem to thoroughly support it
77+
7678
TEST_F(ArrayManip, touchClean64) {
7779

7880
const int N = 100;
79-
double* arr = (double*)device->api->allocGlobMem(N * sizeof(double));
81+
long* arr = (long*)device->api->allocGlobMem(N * sizeof(long));
8082
device->algorithms.touchMemory(arr, N, true, device->api->getDefaultStream());
81-
std::vector<double> hostVector(N, 1);
83+
std::vector<long> hostVector(N, 1);
8284

8385
device->api->copyFromAsync(
84-
&hostVector[0], arr, N * sizeof(double), device->api->getDefaultStream());
86+
&hostVector[0], arr, N * sizeof(long), device->api->getDefaultStream());
8587

8688
device->api->syncDefaultStreamWithHost();
8789

@@ -95,14 +97,13 @@ TEST_F(ArrayManip, touchClean64) {
9597
TEST_F(ArrayManip, touchNoClean64) {
9698

9799
const int N = 100;
98-
double* arr = (double*)device->api->allocGlobMem(N * sizeof(double));
99-
std::vector<double> hostVector(N, 0);
100+
long* arr = (long*)device->api->allocGlobMem(N * sizeof(long));
101+
std::vector<long> hostVector(N, 0);
100102

101-
device->api->copyToAsync(
102-
arr, &hostVector[0], N * sizeof(double), device->api->getDefaultStream());
103+
device->api->copyToAsync(arr, &hostVector[0], N * sizeof(long), device->api->getDefaultStream());
103104
device->algorithms.touchMemory(arr, N, false, device->api->getDefaultStream());
104105
device->api->copyFromAsync(
105-
&hostVector[0], arr, N * sizeof(double), device->api->getDefaultStream());
106+
&hostVector[0], arr, N * sizeof(long), device->api->getDefaultStream());
106107

107108
device->api->syncDefaultStreamWithHost();
108109

tests/batch_manip.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BatchManip : public BaseTestSuite {
3232
std::forward<F>(inner)(batch, data);
3333

3434
device->api->freeGlobMem(data);
35-
device->api->freeGlobMem(batch);
35+
device->api->freeUnifiedMem(batch);
3636
}
3737
};
3838

@@ -166,14 +166,14 @@ TEST_F(BatchManip, uniformToScatter32) {
166166
TEST_F(BatchManip, fill64) {
167167
const int N = 100;
168168
const int M = 120;
169-
testWrapper<double>(N, M, false, [&](double** batch, double* data) {
170-
double scalar = 502;
169+
testWrapper<long>(N, M, false, [&](long** batch, long* data) {
170+
long scalar = 502;
171171

172172
device->algorithms.setToValue(batch, scalar, M, N, device->api->getDefaultStream());
173173

174-
std::vector<double> hostVector(N * M, 0);
174+
std::vector<long> hostVector(N * M, 0);
175175
device->api->copyFromAsync(
176-
&hostVector[0], data, N * M * sizeof(double), device->api->getDefaultStream());
176+
&hostVector[0], data, N * M * sizeof(long), device->api->getDefaultStream());
177177

178178
device->api->syncDefaultStreamWithHost();
179179

@@ -186,12 +186,12 @@ TEST_F(BatchManip, fill64) {
186186
TEST_F(BatchManip, touchClean64) {
187187
const int N = 100;
188188
const int M = 120;
189-
testWrapper<double>(N, M, false, [&](double** batch, double* data) {
189+
testWrapper<long>(N, M, false, [&](long** batch, long* data) {
190190
device->algorithms.touchBatchedMemory(batch, M, N, true, device->api->getDefaultStream());
191-
std::vector<double> hostVector(N * M, 1);
191+
std::vector<long> hostVector(N * M, 1);
192192

193193
device->api->copyFromAsync(
194-
&hostVector[0], data, M * N * sizeof(double), device->api->getDefaultStream());
194+
&hostVector[0], data, M * N * sizeof(long), device->api->getDefaultStream());
195195

196196
device->api->syncDefaultStreamWithHost();
197197

@@ -200,14 +200,14 @@ TEST_F(BatchManip, touchClean64) {
200200
}
201201
});
202202

203-
testWrapper<double>(N, M, true, [&](double** batch, double* data) {
204-
std::vector<double> hostVector(N * M, 1);
203+
testWrapper<long>(N, M, true, [&](long** batch, long* data) {
204+
std::vector<long> hostVector(N * M, 1);
205205

206206
device->api->copyToAsync(
207-
data, &hostVector[0], N * M * sizeof(double), device->api->getDefaultStream());
207+
data, &hostVector[0], N * M * sizeof(long), device->api->getDefaultStream());
208208
device->algorithms.touchBatchedMemory(batch, M, N, true, device->api->getDefaultStream());
209209
device->api->copyFromAsync(
210-
&hostVector[0], data, M * N * sizeof(double), device->api->getDefaultStream());
210+
&hostVector[0], data, M * N * sizeof(long), device->api->getDefaultStream());
211211

212212
device->api->syncDefaultStreamWithHost();
213213

@@ -226,14 +226,14 @@ TEST_F(BatchManip, touchClean64) {
226226
TEST_F(BatchManip, touchNoClean64) {
227227
const int N = 100;
228228
const int M = 120;
229-
testWrapper<double>(N, M, false, [&](double** batch, double* data) {
230-
std::vector<double> hostVector(N * M, 1);
229+
testWrapper<long>(N, M, false, [&](long** batch, long* data) {
230+
std::vector<long> hostVector(N * M, 1);
231231

232232
device->api->copyToAsync(
233-
data, &hostVector[0], N * M * sizeof(double), device->api->getDefaultStream());
233+
data, &hostVector[0], N * M * sizeof(long), device->api->getDefaultStream());
234234
device->algorithms.touchBatchedMemory(batch, M, N, false, device->api->getDefaultStream());
235235
device->api->copyFromAsync(
236-
&hostVector[0], data, N * M * sizeof(double), device->api->getDefaultStream());
236+
&hostVector[0], data, N * M * sizeof(long), device->api->getDefaultStream());
237237

238238
device->api->syncDefaultStreamWithHost();
239239

@@ -247,16 +247,16 @@ TEST_F(BatchManip, scatterToUniform64) {
247247
const int N = 100;
248248
const int M = 120;
249249

250-
double* data2 = (double*)device->api->allocGlobMem(N * M * sizeof(double));
251-
testWrapper<double>(N, M, false, [&](double** batch, double* data) {
252-
std::vector<double> hostVector(N * M, 1);
250+
long* data2 = (long*)device->api->allocGlobMem(N * M * sizeof(long));
251+
testWrapper<long>(N, M, false, [&](long** batch, long* data) {
252+
std::vector<long> hostVector(N * M, 1);
253253

254254
device->api->copyToAsync(
255-
data, &hostVector[0], N * M * sizeof(double), device->api->getDefaultStream());
255+
data, &hostVector[0], N * M * sizeof(long), device->api->getDefaultStream());
256256
device->algorithms.copyScatterToUniform(
257-
const_cast<const double**>(batch), data2, M, M, N, device->api->getDefaultStream());
257+
const_cast<const long**>(batch), data2, M, M, N, device->api->getDefaultStream());
258258
device->api->copyFromAsync(
259-
&hostVector[0], data2, N * M * sizeof(double), device->api->getDefaultStream());
259+
&hostVector[0], data2, N * M * sizeof(long), device->api->getDefaultStream());
260260

261261
device->api->syncDefaultStreamWithHost();
262262

@@ -271,15 +271,15 @@ TEST_F(BatchManip, uniformToScatter64) {
271271
const int N = 100;
272272
const int M = 120;
273273

274-
double* data2 = (double*)device->api->allocGlobMem(N * M * sizeof(double));
275-
testWrapper<double>(N, M, false, [&](double** batch, double* data) {
276-
std::vector<double> hostVector(N * M, 1);
274+
long* data2 = (long*)device->api->allocGlobMem(N * M * sizeof(long));
275+
testWrapper<long>(N, M, false, [&](long** batch, long* data) {
276+
std::vector<long> hostVector(N * M, 1);
277277

278278
device->api->copyToAsync(
279-
data2, &hostVector[0], N * M * sizeof(double), device->api->getDefaultStream());
279+
data2, &hostVector[0], N * M * sizeof(long), device->api->getDefaultStream());
280280
device->algorithms.copyUniformToScatter(data2, batch, M, M, N, device->api->getDefaultStream());
281281
device->api->copyFromAsync(
282-
&hostVector[0], data, N * M * sizeof(double), device->api->getDefaultStream());
282+
&hostVector[0], data, N * M * sizeof(long), device->api->getDefaultStream());
283283

284284
device->api->syncDefaultStreamWithHost();
285285

tests/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@ int main(int argc, char** argv) {
1414
device.api->setDevice(0);
1515
device.api->initialize();
1616

17-
return RUN_ALL_TESTS();
17+
const auto result = RUN_ALL_TESTS();
18+
19+
device.api->syncDevice();
20+
device.api->finalize();
21+
22+
return result;
1823
}

0 commit comments

Comments
 (0)