Skip to content

Commit e261e8e

Browse files
committed
add clSetKernelArgSVMPointer testing
1 parent 0028372 commit e261e8e

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

samples/11_apitimes/main.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,45 @@ void test_clSetKernelArg(cl::Device& device)
108108
printf("finished in %f ms\n", ms);
109109
}
110110

111+
void test_clSetKernelArgSVMPointer(cl::Device& device)
112+
{
113+
const size_t iterations = 1024 * 1024;
114+
printf("Testing %s (%zu): ", __FUNCTION__, iterations); fflush(stdout);
115+
116+
cl::Context context{device};
117+
118+
std::vector<void*> ptrs;
119+
ptrs.push_back(clSVMAlloc(context(), CL_MEM_READ_WRITE, 128, 0));
120+
ptrs.push_back(clSVMAlloc(context(), CL_MEM_READ_WRITE, 128, 0));
121+
122+
static const char kernelString[] = R"CLC( kernel void Empty(global int* a) {} )CLC";
123+
124+
cl::Program program{context, kernelString};
125+
program.build();
126+
cl::Kernel kernel = cl::Kernel{program, "Empty"};
127+
128+
cl_kernel k = kernel();
129+
130+
auto start = std::chrono::system_clock::now();
131+
for( int i = 0; i < iterations; i++ )
132+
{
133+
clSetKernelArgSVMPointer(
134+
k,
135+
0,
136+
ptrs[i&1] );
137+
}
138+
auto end = std::chrono::system_clock::now();
139+
140+
std::chrono::duration<float> elapsed_seconds = end - start;
141+
float ms = elapsed_seconds.count() * 1000;
142+
printf("finished in %f ms\n", ms);
143+
144+
for (auto ptr : ptrs)
145+
{
146+
clSVMFree(context(), ptr);
147+
}
148+
}
149+
111150
int main(
112151
int argc,
113152
char** argv )
@@ -150,7 +189,8 @@ int main(
150189

151190
//test_clGetDeviceIDs(platforms[platformIndex]);
152191
//test_clGetDeviceInfo(devices[deviceIndex]);
153-
test_clSetKernelArg(devices[deviceIndex]);
192+
//test_clSetKernelArg(devices[deviceIndex]);
193+
test_clSetKernelArgSVMPointer(devices[deviceIndex]);
154194

155195
return 0;
156196
}

0 commit comments

Comments
 (0)