Skip to content

Commit 19cc2ff

Browse files
committed
[Code] Add separate tests for cuda-backend with managed mem
1 parent 240e75d commit 19cc2ff

15 files changed

Lines changed: 216 additions & 1 deletion

cubool/sources/cuda/cuda_instance.cu

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace cubool {
5252
error = cudaMalloc(&ptr, size);
5353
break;
5454
case MemType::Managed:
55-
error = cudaMallocManaged(&ptr, size);
55+
error = cudaMallocManaged(&ptr, size, cudaMemAttachGlobal);
5656
break;
5757
default:
5858
RAISE_ERROR(MemOpFailed, "Failed to fined suitable allocator");
@@ -86,6 +86,10 @@ namespace cubool {
8686
}
8787
}
8888

89+
CudaInstance::MemType CudaInstance::getMemoryType() const {
90+
return mMemoryType;
91+
}
92+
8993
bool CudaInstance::isCudaDeviceSupported() {
9094
int device;
9195
cudaError error = cudaGetDevice(&device);

cubool/sources/cuda/cuda_instance.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace cubool {
5353
void deallocateOnGpu(void* ptr) const;
5454

5555
void syncHostDevice() const;
56+
MemType getMemoryType() const;
5657

5758
static bool isCudaDeviceSupported();
5859
static void queryDeviceCapabilities(cuBool_DeviceCaps& deviceCaps);

cubool/tests/test_matrix_element.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,19 @@ TEST(cuBool_Matrix, SetElementLargeFallback) {
168168
testRun(m, n, CUBOOL_HINT_CPU_BACKEND);
169169
}
170170

171+
TEST(cuBool_Matrix, SetElementSmallManaged) {
172+
cuBool_Index m = 60, n = 100;
173+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
174+
}
175+
176+
TEST(cuBool_Matrix, SetElementMediumManaged) {
177+
cuBool_Index m = 500, n = 1000;
178+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
179+
}
180+
181+
TEST(cuBool_Matrix, SetElementLargeManaged) {
182+
cuBool_Index m = 1000, n = 2000;
183+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
184+
}
185+
171186
CUBOOL_GTEST_MAIN

cubool/tests/test_matrix_ewiseadd.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,19 @@ TEST(cuBool_Matrix, EWiseAddLargeFallback) {
9797
testRun(m, n, CUBOOL_HINT_CPU_BACKEND);
9898
}
9999

100+
TEST(cuBool_Matrix, EWiseAddSmallManaged) {
101+
cuBool_Index m = 60, n = 80;
102+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
103+
}
104+
105+
TEST(cuBool_Matrix, EWiseAddMediumManaged) {
106+
cuBool_Index m = 500, n = 800;
107+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
108+
}
109+
110+
TEST(cuBool_Matrix, EWiseAddLargeManaged) {
111+
cuBool_Index m = 2500, n = 1500;
112+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
113+
}
114+
100115
CUBOOL_GTEST_MAIN

cubool/tests/test_matrix_extract_vector.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,19 @@ TEST(cuBool_Matrix, MatrixExtractVectorLargeFallback) {
119119
testRun(m, n, CUBOOL_HINT_CPU_BACKEND);
120120
}
121121

122+
TEST(cuBool_Matrix, MatrixExtractVectorSmallManaged) {
123+
cuBool_Index m = 1000, n = 2000;
124+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
125+
}
126+
127+
TEST(cuBool_Matrix, MatrixExtractVectorMediumManaged) {
128+
cuBool_Index m = 4000, n = 7000;
129+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
130+
}
131+
132+
TEST(cuBool_Matrix, MatrixExtractVectorLargeManaged) {
133+
cuBool_Index m = 8000, n = 10000;
134+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
135+
}
136+
122137
CUBOOL_GTEST_MAIN

cubool/tests/test_matrix_kronecker.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,25 @@ TEST(cuBool_Matrix, KroneckerLargeFallback) {
109109
testRun(m, n, k, t, step, CUBOOL_HINT_CPU_BACKEND);
110110
}
111111

112+
TEST(cuBool_Matrix, KroneckerSmallManaged) {
113+
cuBool_Index m = 10, n = 20;
114+
cuBool_Index k = 5, t = 15;
115+
float step = 0.05f;
116+
testRun(m, n, k, t, step, CUBOOL_HINT_GPU_MEM_MANAGED);
117+
}
118+
119+
TEST(cuBool_Matrix, KroneckerMediumManaged) {
120+
cuBool_Index m = 100, n = 40;
121+
cuBool_Index k = 30, t = 80;
122+
float step = 0.02f;
123+
testRun(m, n, k, t, step, CUBOOL_HINT_GPU_MEM_MANAGED);
124+
}
125+
126+
TEST(cuBool_Matrix, KroneckerLargeManaged) {
127+
cuBool_Index m = 1000, n = 400;
128+
cuBool_Index k = 300, t = 800;
129+
float step = 0.001f;
130+
testRun(m, n, k, t, step, CUBOOL_HINT_GPU_MEM_MANAGED);
131+
}
132+
112133
CUBOOL_GTEST_MAIN

cubool/tests/test_matrix_mxm.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,19 @@ TEST(cuBool_Matrix, MultiplyLargeFallback) {
137137
testRun(m, t, n, CUBOOL_HINT_CPU_BACKEND);
138138
}
139139

140+
TEST(cuBool_Matrix, MultiplySmallManaged) {
141+
cuBool_Index m = 60, t = 100, n = 80;
142+
testRun(m, t, n, CUBOOL_HINT_GPU_MEM_MANAGED);
143+
}
144+
145+
TEST(cuBool_Matrix, MultiplyMediumManaged) {
146+
cuBool_Index m = 500, t = 1000, n = 800;
147+
testRun(m, t, n, CUBOOL_HINT_GPU_MEM_MANAGED);
148+
}
149+
150+
TEST(cuBool_Matrix, MultiplyLargeManaged) {
151+
cuBool_Index m = 1000, t = 2000, n = 500;
152+
testRun(m, t, n, CUBOOL_HINT_GPU_MEM_MANAGED);
153+
}
154+
140155
CUBOOL_GTEST_MAIN

cubool/tests/test_matrix_reduce.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,22 @@ TEST(cuBool_Matrix, ReduceLargeFallback) {
142142
testRun(m, n, step, CUBOOL_HINT_CPU_BACKEND);
143143
}
144144

145+
TEST(cuBool_Matrix, ReduceSmallManaged) {
146+
cuBool_Index m = 100, n = 200;
147+
float step = 0.05f;
148+
testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED);
149+
}
150+
151+
TEST(cuBool_Matrix, ReduceMediumManaged) {
152+
cuBool_Index m = 400, n = 700;
153+
float step = 0.05f;
154+
testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED);
155+
}
156+
157+
TEST(cuBool_Matrix, ReduceLargeManaged) {
158+
cuBool_Index m = 2000, n = 4000;
159+
float step = 0.01f;
160+
testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED);
161+
}
162+
145163
CUBOOL_GTEST_MAIN

cubool/tests/test_matrix_sub_matrix.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,22 @@ TEST(cuBool_Matrix, SubMatrixExtractLargeFallback) {
100100
testRun(m, n, step, CUBOOL_HINT_CPU_BACKEND);
101101
}
102102

103+
TEST(cuBool_Matrix, SubMatrixExtractSmallManaged) {
104+
cuBool_Index m = 100, n = 200;
105+
float step = 0.05f;
106+
testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED);
107+
}
108+
109+
TEST(cuBool_Matrix, SubMatrixExtractMediumManaged) {
110+
cuBool_Index m = 400, n = 700;
111+
float step = 0.05f;
112+
testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED);
113+
}
114+
115+
TEST(cuBool_Matrix, SubMatrixExtractLargeManaged) {
116+
cuBool_Index m = 2000, n = 4000;
117+
float step = 0.01f;
118+
testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED);
119+
}
120+
103121
CUBOOL_GTEST_MAIN

cubool/tests/test_matrix_transpose.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,19 @@ TEST(cuBool_Matrix, TransposeLargeFallback) {
9292
testRun(m, n, CUBOOL_HINT_CPU_BACKEND);
9393
}
9494

95+
TEST(cuBool_Matrix, TransposeSmallManaged) {
96+
cuBool_Index m = 60, n = 80;
97+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
98+
}
99+
100+
TEST(cuBool_Matrix, TransposeMediumManaged) {
101+
cuBool_Index m = 500, n = 800;
102+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
103+
}
104+
105+
TEST(cuBool_Matrix, TransposeLargeManaged) {
106+
cuBool_Index m = 2500, n = 1500;
107+
testRun(m, n, CUBOOL_HINT_GPU_MEM_MANAGED);
108+
}
109+
95110
CUBOOL_GTEST_MAIN

0 commit comments

Comments
 (0)