-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqrt.hpp
51 lines (43 loc) · 1.08 KB
/
sqrt.hpp
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
/********************************************************************
SQRT.hpp
********************************************************************/
#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>
#include "cv_opencl.hpp"
#define AOCL_ALIGNMENT 64
inline static void* alignedMalloc(size_t size)
{
void *ptr = NULL;
if ( posix_memalign (&ptr, AOCL_ALIGNMENT, size) )
{
fprintf(stderr, "Aligned Malloc failed due to insufficient memory.\n");
exit(-1);
}
return ptr;
}
template <typename T>
cl::Buffer alloc(const CV_OpenCL& cv, int n, T* data){
cl_int err;
cl::Buffer buf;
OCL_CHECK(err, buf = cl::Buffer(cv.ctx,
CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(T) * n,
data,
&err));
if (err != 0) {
exit(1);
}
return buf;
}
typedef struct SQRT
{
CV_OpenCL& cv_opencl;
cl::Buffer x_device;
float* x_host;
int array_size;
SQRT(CV_OpenCL& opencl, int array_size);
void compute_sqrt();
} SQRT;