1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "utests/utest_helper.hpp"
#include <sys/time.h>
void test_copy_buf(size_t sz, size_t src_off, size_t dst_off, size_t cb)
{
unsigned int i;
cl_char* buf0;
OCL_CREATE_BUFFER(buf[0], 0, sz * sizeof(char), NULL);
OCL_CREATE_BUFFER(buf[1], 0, sz * sizeof(char), NULL);
buf0 = (cl_char *)clEnqueueMapBuffer(queue, buf[0], CL_TRUE, CL_MAP_WRITE, 0, sizeof(char), 0, NULL, NULL, NULL);
for (i=0; i < sz; i++) {
buf0[i]=(rand() & 0xFF);
}
clEnqueueUnmapMemObject(queue, buf[0], buf0, 0, NULL, NULL);
if (src_off + cb > sz || dst_off + cb > sz) {
/* Expect Error. */
OCL_ASSERT(clEnqueueCopyBuffer(queue, buf[0], buf[1],
src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
return;
}
OCL_ASSERT(CL_SUCCESS == clEnqueueCopyBuffer(queue, buf[0], buf[1],
src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
}
int tim_subtract(struct timeval *y, struct timeval *x, struct timeval *result){
if ( x->tv_sec > y->tv_sec )
return -1;
if ((x->tv_sec == y->tv_sec) && (x->tv_usec > y->tv_usec))
return -1;
if ( result != NULL){
result->tv_sec = ( y->tv_sec - x->tv_sec );
result->tv_usec = ( y->tv_usec - x->tv_usec );
if (result->tv_usec < 0){
result->tv_sec --;
result->tv_usec += 1000000;
}
}
int msec = 1000.0*(y->tv_sec - x->tv_sec) + (y->tv_usec - x->tv_usec)/1000.0;
return msec;
}
int enqueue_copy_buf(void)
{
size_t i;
const size_t sz = 127 *1023 * 1023;
struct timeval start,stop;
gettimeofday(&start,0);
for (i=0; i<10; i++) {
test_copy_buf(sz, 0, 0, sz);
}
gettimeofday(&stop,0);
return tim_subtract(&stop, &start, 0);
}
MAKE_BENCHMARK_FROM_FUNCTION(enqueue_copy_buf);
|