|
@@ -40,55 +40,55 @@ double KC; //: the kernel compilation time
|
|
@date: 24/03/2011
|
|
@date: 24/03/2011
|
|
------------------------------------------------------------*/
|
|
------------------------------------------------------------*/
|
|
struct _clDeviceProp{
|
|
struct _clDeviceProp{
|
|
-/*CL_DEVICE_ADDRESS_BITS
|
|
|
|
-CL_DEVICE_AVAILABLE
|
|
|
|
-CL_DEVICE_COMPILER_AVAILABLE
|
|
|
|
-CL_DEVICE_ENDIAN_LITTLE
|
|
|
|
-CL_DEVICE_ERROR_CORRECTION_SUPPORT
|
|
|
|
-CL_DEVICE_EXECUTION_CAPABILITIES
|
|
|
|
|
|
+/*CL_DEVICE_ADDRESS_BITS
|
|
|
|
+CL_DEVICE_AVAILABLE
|
|
|
|
+CL_DEVICE_COMPILER_AVAILABLE
|
|
|
|
+CL_DEVICE_ENDIAN_LITTLE
|
|
|
|
+CL_DEVICE_ERROR_CORRECTION_SUPPORT
|
|
|
|
+CL_DEVICE_EXECUTION_CAPABILITIES
|
|
CL_DEVICE_EXTENSIONS
|
|
CL_DEVICE_EXTENSIONS
|
|
-CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
|
|
|
|
-CL_DEVICE_GLOBAL_MEM_CACHE_TYPE
|
|
|
|
-CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
|
|
|
|
-CL_DEVICE_GLOBAL_MEM_SIZE
|
|
|
|
-CL_DEVICE_IMAGE_SUPPORT
|
|
|
|
-CL_DEVICE_IMAGE2D_MAX_HEIGHT
|
|
|
|
-CL_DEVICE_IMAGE2D_MAX_WIDTH
|
|
|
|
-CL_DEVICE_IMAGE3D_MAX_DEPTH
|
|
|
|
-CL_DEVICE_IMAGE3D_MAX_HEIGHT
|
|
|
|
-CL_DEVICE_IMAGE3D_MAX_WIDTH
|
|
|
|
-CL_DEVICE_LOCAL_MEM_SIZE
|
|
|
|
-CL_DEVICE_LOCAL_MEM_TYPE
|
|
|
|
-CL_DEVICE_MAX_CLOCK_FREQUENCY
|
|
|
|
-CL_DEVICE_MAX_COMPUTE_UNITS
|
|
|
|
-CL_DEVICE_MAX_CONSTANT_ARGS
|
|
|
|
-CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
|
|
|
|
-CL_DEVICE_MAX_MEM_ALLOC_SIZE
|
|
|
|
-CL_DEVICE_MAX_PARAMETER_SIZE
|
|
|
|
-CL_DEVICE_MAX_READ_IMAGE_ARGS
|
|
|
|
-CL_DEVICE_MAX_SAMPLERS
|
|
|
|
-CL_DEVICE_MAX_WORK_GROUP_SIZE
|
|
|
|
-CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
|
|
|
|
-CL_DEVICE_MAX_WORK_ITEM_SIZES
|
|
|
|
-CL_DEVICE_MAX_WRITE_IMAGE_ARGS
|
|
|
|
-CL_DEVICE_MEM_BASE_ADDR_ALIGN
|
|
|
|
-CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
|
|
|
|
-CL_DEVICE_NAME
|
|
|
|
|
|
+CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
|
|
|
|
+CL_DEVICE_GLOBAL_MEM_CACHE_TYPE
|
|
|
|
+CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
|
|
|
|
+CL_DEVICE_GLOBAL_MEM_SIZE
|
|
|
|
+CL_DEVICE_IMAGE_SUPPORT
|
|
|
|
+CL_DEVICE_IMAGE2D_MAX_HEIGHT
|
|
|
|
+CL_DEVICE_IMAGE2D_MAX_WIDTH
|
|
|
|
+CL_DEVICE_IMAGE3D_MAX_DEPTH
|
|
|
|
+CL_DEVICE_IMAGE3D_MAX_HEIGHT
|
|
|
|
+CL_DEVICE_IMAGE3D_MAX_WIDTH
|
|
|
|
+CL_DEVICE_LOCAL_MEM_SIZE
|
|
|
|
+CL_DEVICE_LOCAL_MEM_TYPE
|
|
|
|
+CL_DEVICE_MAX_CLOCK_FREQUENCY
|
|
|
|
+CL_DEVICE_MAX_COMPUTE_UNITS
|
|
|
|
+CL_DEVICE_MAX_CONSTANT_ARGS
|
|
|
|
+CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
|
|
|
|
+CL_DEVICE_MAX_MEM_ALLOC_SIZE
|
|
|
|
+CL_DEVICE_MAX_PARAMETER_SIZE
|
|
|
|
+CL_DEVICE_MAX_READ_IMAGE_ARGS
|
|
|
|
+CL_DEVICE_MAX_SAMPLERS
|
|
|
|
+CL_DEVICE_MAX_WORK_GROUP_SIZE
|
|
|
|
+CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
|
|
|
|
+CL_DEVICE_MAX_WORK_ITEM_SIZES
|
|
|
|
+CL_DEVICE_MAX_WRITE_IMAGE_ARGS
|
|
|
|
+CL_DEVICE_MEM_BASE_ADDR_ALIGN
|
|
|
|
+CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
|
|
|
|
+CL_DEVICE_NAME
|
|
CL_DEVICE_PLATFORM
|
|
CL_DEVICE_PLATFORM
|
|
-CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
|
|
|
|
-CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
|
|
|
|
-CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
|
|
|
|
-CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
|
|
|
|
-CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
|
|
|
|
-CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
|
|
|
|
-CL_DEVICE_PROFILE
|
|
|
|
-CL_DEVICE_PROFILING_TIMER_RESOLUTION
|
|
|
|
-CL_DEVICE_QUEUE_PROPERTIES
|
|
|
|
-CL_DEVICE_SINGLE_FP_CONFIG
|
|
|
|
-CL_DEVICE_TYPE
|
|
|
|
-CL_DEVICE_VENDOR_ID
|
|
|
|
-CL_DEVICE_VENDOR
|
|
|
|
-CL_DEVICE_VERSION
|
|
|
|
|
|
+CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
|
|
|
|
+CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
|
|
|
|
+CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
|
|
|
|
+CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
|
|
|
|
+CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
|
|
|
|
+CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
|
|
|
|
+CL_DEVICE_PROFILE
|
|
|
|
+CL_DEVICE_PROFILING_TIMER_RESOLUTION
|
|
|
|
+CL_DEVICE_QUEUE_PROPERTIES
|
|
|
|
+CL_DEVICE_SINGLE_FP_CONFIG
|
|
|
|
+CL_DEVICE_TYPE
|
|
|
|
+CL_DEVICE_VENDOR_ID
|
|
|
|
+CL_DEVICE_VENDOR
|
|
|
|
+CL_DEVICE_VERSION
|
|
CL_DRIVER_VERSION*/
|
|
CL_DRIVER_VERSION*/
|
|
char device_name[100];
|
|
char device_name[100];
|
|
};
|
|
};
|
|
@@ -117,14 +117,14 @@ int number_devices = 0;
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
/*------------------------------------------------------------
|
|
@function: select device to use
|
|
@function: select device to use
|
|
- @params:
|
|
|
|
|
|
+ @params:
|
|
size: the index of device to be used
|
|
size: the index of device to be used
|
|
@return: NULL
|
|
@return: NULL
|
|
@date: 24/03/2011
|
|
@date: 24/03/2011
|
|
------------------------------------------------------------*/
|
|
------------------------------------------------------------*/
|
|
void _clSetDevice(int idx) throw(string){
|
|
void _clSetDevice(int idx) throw(string){
|
|
|
|
|
|
- cl_int resultCL;
|
|
|
|
|
|
+ cl_int resultCL;
|
|
oclHandles.context = NULL;
|
|
oclHandles.context = NULL;
|
|
oclHandles.devices = NULL;
|
|
oclHandles.devices = NULL;
|
|
oclHandles.queue = NULL;
|
|
oclHandles.queue = NULL;
|
|
@@ -152,29 +152,29 @@ void _clSetDevice(int idx) throw(string){
|
|
|
|
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ALL, 0, NULL, &deviceListSize);
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ALL, 0, NULL, &deviceListSize);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
- throw(string("exception in _clInit -> clGetDeviceIDs"));
|
|
|
|
|
|
+ throw(string("exception in _clInit -> clGetDeviceIDs"));
|
|
}
|
|
}
|
|
if (deviceListSize == 0)
|
|
if (deviceListSize == 0)
|
|
throw(string("InitCL()::Error: No devices found."));
|
|
throw(string("InitCL()::Error: No devices found."));
|
|
-
|
|
|
|
|
|
+
|
|
if(idx>(deviceListSize-1))
|
|
if(idx>(deviceListSize-1))
|
|
throw(string(":invalid device ID:"));
|
|
throw(string(":invalid device ID:"));
|
|
device_id_inused = idx;
|
|
device_id_inused = idx;
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
/*------------------------------------------------------------
|
|
@function: get device properties indexed by 'idx'
|
|
@function: get device properties indexed by 'idx'
|
|
- @params:
|
|
|
|
|
|
+ @params:
|
|
idx: device index
|
|
idx: device index
|
|
prop: output properties
|
|
prop: output properties
|
|
@return: prop
|
|
@return: prop
|
|
@date: 24/03/2011
|
|
@date: 24/03/2011
|
|
------------------------------------------------------------*/
|
|
------------------------------------------------------------*/
|
|
void _clGetDeviceProperties(int idx, _clDeviceProp *prop) throw(string){
|
|
void _clGetDeviceProperties(int idx, _clDeviceProp *prop) throw(string){
|
|
-
|
|
|
|
|
|
+
|
|
oclHandles.cl_status= clGetDeviceInfo(oclHandles.devices[idx], CL_DEVICE_NAME, 100, prop->device_name, NULL);
|
|
oclHandles.cl_status= clGetDeviceInfo(oclHandles.devices[idx], CL_DEVICE_NAME, 100, prop->device_name, NULL);
|
|
-
|
|
|
|
|
|
+
|
|
#ifdef ERRMSG
|
|
#ifdef ERRMSG
|
|
if(oclHandles.cl_status != CL_SUCCESS){
|
|
if(oclHandles.cl_status != CL_SUCCESS){
|
|
oclHandles.error_str = "exception in _clGetDeviceProperties-> ";
|
|
oclHandles.error_str = "exception in _clGetDeviceProperties-> ";
|
|
@@ -184,13 +184,13 @@ void _clGetDeviceProperties(int idx, _clDeviceProp *prop) throw(string){
|
|
break;
|
|
break;
|
|
case CL_INVALID_VALUE:
|
|
case CL_INVALID_VALUE:
|
|
oclHandles.error_str += "CL_INVALID_VALUE";
|
|
oclHandles.error_str += "CL_INVALID_VALUE";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
oclHandles.error_str += "unknown reasons";
|
|
oclHandles.error_str += "unknown reasons";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
- }
|
|
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
|
|
|
|
@@ -217,7 +217,7 @@ string FileToString(const string fileName){
|
|
f.read(str, fileSize);
|
|
f.read(str, fileSize);
|
|
f.close();
|
|
f.close();
|
|
str[size] = '\0';
|
|
str[size] = '\0';
|
|
-
|
|
|
|
|
|
+
|
|
s = str;
|
|
s = str;
|
|
delete [] str;
|
|
delete [] str;
|
|
return s;
|
|
return s;
|
|
@@ -246,6 +246,8 @@ string FileToString(const string fileName){
|
|
------------------------------------------------------------*/
|
|
------------------------------------------------------------*/
|
|
char device_type[3];
|
|
char device_type[3];
|
|
int device_id = 0;
|
|
int device_id = 0;
|
|
|
|
+int platform_id = 0;
|
|
|
|
+
|
|
void _clCmdParams(int argc, char* argv[]){
|
|
void _clCmdParams(int argc, char* argv[]){
|
|
for (int i = 0; i < argc; ++i){
|
|
for (int i = 0; i < argc; ++i){
|
|
switch (argv[i][1]){
|
|
switch (argv[i][1]){
|
|
@@ -258,15 +260,24 @@ void _clCmdParams(int argc, char* argv[]){
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
- case 'd': //--d stands for device id
|
|
|
|
- if (++i < argc){
|
|
|
|
- sscanf(argv[i], "%d", &device_id);
|
|
|
|
- }
|
|
|
|
- else{
|
|
|
|
- std::cerr << "Could not read argument after option " << argv[i-1] << std::endl;
|
|
|
|
- throw;
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
|
|
+ case 'd': //--d stands for device id
|
|
|
|
+ if (++i < argc){
|
|
|
|
+ sscanf(argv[i], "%d", &device_id);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ std::cerr << "Could not read argument after option " << argv[i-1] << std::endl;
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 'p': //--d stands for device id
|
|
|
|
+ if (++i < argc){
|
|
|
|
+ sscanf(argv[i], "%d", &platform_id);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ std::cerr << "Could not read argument after option " << argv[i-1] << std::endl;
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
;
|
|
;
|
|
}
|
|
}
|
|
@@ -275,9 +286,9 @@ void _clCmdParams(int argc, char* argv[]){
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
/*------------------------------------------------------------
|
|
@function: Initlize CL objects
|
|
@function: Initlize CL objects
|
|
- @params:
|
|
|
|
|
|
+ @params:
|
|
device_id: device id
|
|
device_id: device id
|
|
- device_type: the types of devices, e.g. CPU, GPU, ACCERLERATOR,...
|
|
|
|
|
|
+ device_type: the types of devices, e.g. CPU, GPU, ACCERLERATOR,...
|
|
(1) -t cpu/gpu/acc -d 0/1/2/...
|
|
(1) -t cpu/gpu/acc -d 0/1/2/...
|
|
(2) -t cpu/gpu/acc [-d 0]
|
|
(2) -t cpu/gpu/acc [-d 0]
|
|
(3) [-t default] -d 0/1/2/...
|
|
(3) [-t default] -d 0/1/2/...
|
|
@@ -285,7 +296,7 @@ void _clCmdParams(int argc, char* argv[]){
|
|
@return:
|
|
@return:
|
|
@description:
|
|
@description:
|
|
there are 5 steps to initialize all the OpenCL objects needed,
|
|
there are 5 steps to initialize all the OpenCL objects needed,
|
|
- @revised:
|
|
|
|
|
|
+ @revised:
|
|
get the number of devices and devices have no relationship with context
|
|
get the number of devices and devices have no relationship with context
|
|
@date: 24/03/2011
|
|
@date: 24/03/2011
|
|
------------------------------------------------------------*/
|
|
------------------------------------------------------------*/
|
|
@@ -303,13 +314,13 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
KE = 0;
|
|
KE = 0;
|
|
KC = 0;
|
|
KC = 0;
|
|
#endif
|
|
#endif
|
|
- int DEVICE_ID_INUSED = 0;
|
|
|
|
|
|
+ int DEVICE_ID_INUSED = 0;
|
|
_clDeviceProp prop;
|
|
_clDeviceProp prop;
|
|
#ifdef PROFILE_
|
|
#ifdef PROFILE_
|
|
double t1 = gettime();
|
|
double t1 = gettime();
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- cl_int resultCL;
|
|
|
|
|
|
+ cl_int resultCL;
|
|
oclHandles.context = NULL;
|
|
oclHandles.context = NULL;
|
|
oclHandles.devices = NULL;
|
|
oclHandles.devices = NULL;
|
|
oclHandles.queue = NULL;
|
|
oclHandles.queue = NULL;
|
|
@@ -339,8 +350,8 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
if (resultCL != CL_SUCCESS)
|
|
if (resultCL != CL_SUCCESS)
|
|
throw (string("InitCL()::Error: Getting platform ids (clGetPlatformIDs)"));
|
|
throw (string("InitCL()::Error: Getting platform ids (clGetPlatformIDs)"));
|
|
|
|
|
|
- // Select the target platform. Default: first platform
|
|
|
|
- targetPlatform = allPlatforms[1];
|
|
|
|
|
|
+ // Select the target platform. Default: first platform
|
|
|
|
+ targetPlatform = allPlatforms[platform_id];
|
|
for (int i = 0; i < numPlatforms; i++)
|
|
for (int i = 0; i < numPlatforms; i++)
|
|
{
|
|
{
|
|
char pbuff[128];
|
|
char pbuff[128];
|
|
@@ -360,74 +371,74 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
}
|
|
}
|
|
free(allPlatforms);
|
|
free(allPlatforms);
|
|
//-----------------------------------------------
|
|
//-----------------------------------------------
|
|
- //--cambine-2: detect OpenCL devices
|
|
|
|
- // First, get the size of device list
|
|
|
|
|
|
+ //--cambine-2: detect OpenCL devices
|
|
|
|
+ // First, get the size of device list
|
|
if(device_type.compare("")!=0){
|
|
if(device_type.compare("")!=0){
|
|
if(device_type.compare("cpu")==0){
|
|
if(device_type.compare("cpu")==0){
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_CPU, 0, NULL, &deviceListSize);
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_CPU, 0, NULL, &deviceListSize);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
- throw(string("exception in _clInit -> clGetDeviceIDs -> CPU"));
|
|
|
|
|
|
+ throw(string("exception in _clInit -> clGetDeviceIDs -> CPU"));
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if(device_type.compare("gpu")==0){
|
|
|
|
|
|
+ }
|
|
|
|
+ if(device_type.compare("gpu")==0){
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_GPU, 0, NULL, &deviceListSize);
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_GPU, 0, NULL, &deviceListSize);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
- throw(string("exception in _clInit -> clGetDeviceIDs -> GPU"));
|
|
|
|
|
|
+ throw(string("exception in _clInit -> clGetDeviceIDs -> GPU"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(device_type.compare("acc")==0){
|
|
if(device_type.compare("acc")==0){
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ACCELERATOR, 0, NULL, &deviceListSize);
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ACCELERATOR, 0, NULL, &deviceListSize);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
- throw(string("exception in _clInit -> clGetDeviceIDs -> ACCELERATOR"));
|
|
|
|
|
|
+ throw(string("exception in _clInit -> clGetDeviceIDs -> ACCELERATOR"));
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ALL, 0, NULL, &deviceListSize);
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ALL, 0, NULL, &deviceListSize);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
- throw(string("exception in _clInit -> clGetDeviceIDs -> ALL"));
|
|
|
|
|
|
+ throw(string("exception in _clInit -> clGetDeviceIDs -> ALL"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (deviceListSize == 0)
|
|
if (deviceListSize == 0)
|
|
throw(string("InitCL()::Error: No devices found."));
|
|
throw(string("InitCL()::Error: No devices found."));
|
|
-
|
|
|
|
|
|
+
|
|
#ifdef DEV_INFO
|
|
#ifdef DEV_INFO
|
|
std::cout<<"--cambine: number of device="<<deviceListSize<<std::endl;
|
|
std::cout<<"--cambine: number of device="<<deviceListSize<<std::endl;
|
|
#endif
|
|
#endif
|
|
number_devices = deviceListSize;
|
|
number_devices = deviceListSize;
|
|
- // Now, allocate the device list
|
|
|
|
|
|
+ // Now, allocate the device list
|
|
// oclHandles.devices = (cl_device_id *)malloc(deviceListSize);
|
|
// oclHandles.devices = (cl_device_id *)malloc(deviceListSize);
|
|
oclHandles.devices = (cl_device_id *)malloc(sizeof(cl_device_id) * deviceListSize);
|
|
oclHandles.devices = (cl_device_id *)malloc(sizeof(cl_device_id) * deviceListSize);
|
|
|
|
|
|
if (oclHandles.devices == 0)
|
|
if (oclHandles.devices == 0)
|
|
throw(string("InitCL()::Error: Could not allocate memory."));
|
|
throw(string("InitCL()::Error: Could not allocate memory."));
|
|
|
|
|
|
- // Next, get the device list data
|
|
|
|
|
|
+ // Next, get the device list data
|
|
if(device_type.compare("")!=0){
|
|
if(device_type.compare("")!=0){
|
|
if(device_type.compare("cpu")==0){
|
|
if(device_type.compare("cpu")==0){
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_CPU, deviceListSize, oclHandles.devices, NULL);
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_CPU, deviceListSize, oclHandles.devices, NULL);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
- throw(string("exception in _clInit -> clGetDeviceIDs -> CPU ->2"));
|
|
|
|
|
|
+ throw(string("exception in _clInit -> clGetDeviceIDs -> CPU ->2"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(device_type.compare("gpu")==0){
|
|
if(device_type.compare("gpu")==0){
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_GPU, deviceListSize, oclHandles.devices, NULL);
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_GPU, deviceListSize, oclHandles.devices, NULL);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
- throw(string("exception in _clInit -> clGetDeviceIDs -> GPU -> 2"));
|
|
|
|
|
|
+ throw(string("exception in _clInit -> clGetDeviceIDs -> GPU -> 2"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(device_type.compare("acc")==0){
|
|
if(device_type.compare("acc")==0){
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ACCELERATOR, deviceListSize, oclHandles.devices, NULL);
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ACCELERATOR, deviceListSize, oclHandles.devices, NULL);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
- throw(string("exception in _clInit -> clGetDeviceIDs -> ACCELERATOR -> 2"));
|
|
|
|
|
|
+ throw(string("exception in _clInit -> clGetDeviceIDs -> ACCELERATOR -> 2"));
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ALL, deviceListSize, oclHandles.devices, NULL);
|
|
oclHandles.cl_status = clGetDeviceIDs(targetPlatform, CL_DEVICE_TYPE_ALL, deviceListSize, oclHandles.devices, NULL);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
- throw(string("exception in _clInit -> clGetDeviceIDs -> ALL -> 2"));
|
|
|
|
|
|
+ throw(string("exception in _clInit -> clGetDeviceIDs -> ALL -> 2"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(device_id!=0){
|
|
if(device_id!=0){
|
|
@@ -435,23 +446,23 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
throw(string("Invalidate device id"));
|
|
throw(string("Invalidate device id"));
|
|
DEVICE_ID_INUSED = device_id;
|
|
DEVICE_ID_INUSED = device_id;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
_clGetDeviceProperties(DEVICE_ID_INUSED, &prop);
|
|
_clGetDeviceProperties(DEVICE_ID_INUSED, &prop);
|
|
std::cout<<"--cambine: device name="<<prop.device_name<<std::endl;
|
|
std::cout<<"--cambine: device name="<<prop.device_name<<std::endl;
|
|
-
|
|
|
|
|
|
+
|
|
#ifdef DEV_INFO
|
|
#ifdef DEV_INFO
|
|
std::cout<<"--cambine: return device list successfully!"<<std::endl;
|
|
std::cout<<"--cambine: return device list successfully!"<<std::endl;
|
|
-#endif
|
|
|
|
-
|
|
|
|
|
|
+#endif
|
|
|
|
+
|
|
//-----------------------------------------------
|
|
//-----------------------------------------------
|
|
//--cambine-3: create an OpenCL context
|
|
//--cambine-3: create an OpenCL context
|
|
#ifdef DEV_INFO
|
|
#ifdef DEV_INFO
|
|
std::cout<<"--cambine: before creating context"<<std::endl;
|
|
std::cout<<"--cambine: before creating context"<<std::endl;
|
|
#endif
|
|
#endif
|
|
cl_context_properties cprops[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)targetPlatform, 0 };
|
|
cl_context_properties cprops[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)targetPlatform, 0 };
|
|
- oclHandles.context = clCreateContext(0,
|
|
|
|
- deviceListSize,
|
|
|
|
- oclHandles.devices,
|
|
|
|
|
|
+ oclHandles.context = clCreateContext(0,
|
|
|
|
+ deviceListSize,
|
|
|
|
+ oclHandles.devices,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
&resultCL);
|
|
&resultCL);
|
|
@@ -463,10 +474,10 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
#endif
|
|
#endif
|
|
|
|
|
|
//-----------------------------------------------
|
|
//-----------------------------------------------
|
|
- //--cambine-4: Create an OpenCL command queue
|
|
|
|
- oclHandles.queue = clCreateCommandQueue(oclHandles.context,
|
|
|
|
- oclHandles.devices[DEVICE_ID_INUSED],
|
|
|
|
- 0,
|
|
|
|
|
|
+ //--cambine-4: Create an OpenCL command queue
|
|
|
|
+ oclHandles.queue = clCreateCommandQueue(oclHandles.context,
|
|
|
|
+ oclHandles.devices[DEVICE_ID_INUSED],
|
|
|
|
+ 0,
|
|
&resultCL);
|
|
&resultCL);
|
|
|
|
|
|
if ((resultCL != CL_SUCCESS) || (oclHandles.queue == NULL))
|
|
if ((resultCL != CL_SUCCESS) || (oclHandles.queue == NULL))
|
|
@@ -481,40 +492,40 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
const char * source = source_str.c_str();
|
|
const char * source = source_str.c_str();
|
|
size_t sourceSize[] = { source_str.length() };
|
|
size_t sourceSize[] = { source_str.length() };
|
|
|
|
|
|
- oclHandles.program = clCreateProgramWithSource(oclHandles.context,
|
|
|
|
- 1,
|
|
|
|
|
|
+ oclHandles.program = clCreateProgramWithSource(oclHandles.context,
|
|
|
|
+ 1,
|
|
&source,
|
|
&source,
|
|
sourceSize,
|
|
sourceSize,
|
|
&resultCL);
|
|
&resultCL);
|
|
|
|
|
|
if ((resultCL != CL_SUCCESS) || (oclHandles.program == NULL))
|
|
if ((resultCL != CL_SUCCESS) || (oclHandles.program == NULL))
|
|
- throw(string("InitCL()::Error: Loading Binary into cl_program. (clCreateProgramWithBinary)"));
|
|
|
|
|
|
+ throw(string("InitCL()::Error: Loading Binary into cl_program. (clCreateProgramWithBinary)"));
|
|
//insert debug information
|
|
//insert debug information
|
|
std::string options= "";
|
|
std::string options= "";
|
|
//options += " -cl-nv-opt-level=3";
|
|
//options += " -cl-nv-opt-level=3";
|
|
resultCL = clBuildProgram(oclHandles.program, deviceListSize, oclHandles.devices, options.c_str(), NULL, NULL);
|
|
resultCL = clBuildProgram(oclHandles.program, deviceListSize, oclHandles.devices, options.c_str(), NULL, NULL);
|
|
-
|
|
|
|
|
|
+
|
|
if ((resultCL != CL_SUCCESS) || (oclHandles.program == NULL)){
|
|
if ((resultCL != CL_SUCCESS) || (oclHandles.program == NULL)){
|
|
cerr << "InitCL()::Error: In clBuildProgram" << endl;
|
|
cerr << "InitCL()::Error: In clBuildProgram" << endl;
|
|
|
|
|
|
size_t length;
|
|
size_t length;
|
|
- resultCL = clGetProgramBuildInfo(oclHandles.program,
|
|
|
|
- oclHandles.devices[DEVICE_ID_INUSED],
|
|
|
|
- CL_PROGRAM_BUILD_LOG,
|
|
|
|
- 0,
|
|
|
|
- NULL,
|
|
|
|
|
|
+ resultCL = clGetProgramBuildInfo(oclHandles.program,
|
|
|
|
+ oclHandles.devices[DEVICE_ID_INUSED],
|
|
|
|
+ CL_PROGRAM_BUILD_LOG,
|
|
|
|
+ 0,
|
|
|
|
+ NULL,
|
|
&length);
|
|
&length);
|
|
- if(resultCL != CL_SUCCESS)
|
|
|
|
|
|
+ if(resultCL != CL_SUCCESS)
|
|
throw(string("InitCL()::Error: Getting Program build info(clGetProgramBuildInfo)"));
|
|
throw(string("InitCL()::Error: Getting Program build info(clGetProgramBuildInfo)"));
|
|
|
|
|
|
char* buffer = (char*)malloc(length);
|
|
char* buffer = (char*)malloc(length);
|
|
- resultCL = clGetProgramBuildInfo(oclHandles.program,
|
|
|
|
- oclHandles.devices[DEVICE_ID_INUSED],
|
|
|
|
- CL_PROGRAM_BUILD_LOG,
|
|
|
|
- length,
|
|
|
|
- buffer,
|
|
|
|
|
|
+ resultCL = clGetProgramBuildInfo(oclHandles.program,
|
|
|
|
+ oclHandles.devices[DEVICE_ID_INUSED],
|
|
|
|
+ CL_PROGRAM_BUILD_LOG,
|
|
|
|
+ length,
|
|
|
|
+ buffer,
|
|
NULL);
|
|
NULL);
|
|
- if(resultCL != CL_SUCCESS)
|
|
|
|
|
|
+ if(resultCL != CL_SUCCESS)
|
|
throw(string("InitCL()::Error: Getting Program build info(clGetProgramBuildInfo)"));
|
|
throw(string("InitCL()::Error: Getting Program build info(clGetProgramBuildInfo)"));
|
|
|
|
|
|
cerr << buffer << endl;
|
|
cerr << buffer << endl;
|
|
@@ -524,23 +535,23 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
free(buffer);
|
|
free(buffer);
|
|
|
|
|
|
throw(string("InitCL()::Error: Building Program (clBuildProgram)"));
|
|
throw(string("InitCL()::Error: Building Program (clBuildProgram)"));
|
|
- }
|
|
|
|
|
|
+ }
|
|
#ifdef PROFILE_
|
|
#ifdef PROFILE_
|
|
double t3 = gettime();
|
|
double t3 = gettime();
|
|
KC += t3 - t2;
|
|
KC += t3 - t2;
|
|
#endif
|
|
#endif
|
|
//get program information in intermediate representation
|
|
//get program information in intermediate representation
|
|
-#ifdef PTX_MSG
|
|
|
|
|
|
+#ifdef PTX_MSG
|
|
size_t binary_sizes[deviceListSize];
|
|
size_t binary_sizes[deviceListSize];
|
|
char * binaries[deviceListSize];
|
|
char * binaries[deviceListSize];
|
|
- //figure out number of devices and the sizes of the binary for each device.
|
|
|
|
|
|
+ //figure out number of devices and the sizes of the binary for each device.
|
|
oclHandles.cl_status = clGetProgramInfo(oclHandles.program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t)*deviceListSize, &binary_sizes, NULL );
|
|
oclHandles.cl_status = clGetProgramInfo(oclHandles.program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t)*deviceListSize, &binary_sizes, NULL );
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
throw(string("--cambine:exception in _InitCL -> clGetProgramInfo-2"));
|
|
throw(string("--cambine:exception in _InitCL -> clGetProgramInfo-2"));
|
|
}
|
|
}
|
|
|
|
|
|
std::cout<<"--cambine:"<<binary_sizes<<std::endl;
|
|
std::cout<<"--cambine:"<<binary_sizes<<std::endl;
|
|
- //copy over all of the generated binaries.
|
|
|
|
|
|
+ //copy over all of the generated binaries.
|
|
for(int i=0;i<deviceListSize;i++)
|
|
for(int i=0;i<deviceListSize;i++)
|
|
binaries[i] = (char *)malloc( sizeof(char)*(binary_sizes[i]+1));
|
|
binaries[i] = (char *)malloc( sizeof(char)*(binary_sizes[i]+1));
|
|
oclHandles.cl_status = clGetProgramInfo(oclHandles.program, CL_PROGRAM_BINARIES, sizeof(char *)*deviceListSize, binaries, NULL );
|
|
oclHandles.cl_status = clGetProgramInfo(oclHandles.program, CL_PROGRAM_BINARIES, sizeof(char *)*deviceListSize, binaries, NULL );
|
|
@@ -563,7 +574,7 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
|
|
|
|
for (int nKernel = 0; nKernel < total_kernels; nKernel++)
|
|
for (int nKernel = 0; nKernel < total_kernels; nKernel++)
|
|
{
|
|
{
|
|
- // get a kernel object handle for a kernel with the given name
|
|
|
|
|
|
+ // get a kernel object handle for a kernel with the given name
|
|
cl_kernel kernel = clCreateKernel(oclHandles.program,
|
|
cl_kernel kernel = clCreateKernel(oclHandles.program,
|
|
(kernel_names[nKernel]).c_str(),
|
|
(kernel_names[nKernel]).c_str(),
|
|
&resultCL);
|
|
&resultCL);
|
|
@@ -583,7 +594,7 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
oclHandles.cl_status = clGetProgramBuildInfo(oclHandles.program, oclHandles.devices[DEVICE_ID_INUSED], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
|
|
oclHandles.cl_status = clGetProgramBuildInfo(oclHandles.program, oclHandles.devices[DEVICE_ID_INUSED], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
throw(string("exceptions in _InitCL -> getting resource information"));
|
|
throw(string("exceptions in _InitCL -> getting resource information"));
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
build_log = (char *)malloc(ret_val_size+1);
|
|
build_log = (char *)malloc(ret_val_size+1);
|
|
oclHandles.cl_status = clGetProgramBuildInfo(oclHandles.program, oclHandles.devices[DEVICE_ID_INUSED], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
|
|
oclHandles.cl_status = clGetProgramBuildInfo(oclHandles.program, oclHandles.devices[DEVICE_ID_INUSED], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
|
|
@@ -664,7 +675,7 @@ void _clRelease()
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
/*------------------------------------------------------------
|
|
@function: create read and write buffer for devices
|
|
@function: create read and write buffer for devices
|
|
- @params:
|
|
|
|
|
|
+ @params:
|
|
size: the size of device memory to be allocated
|
|
size: the size of device memory to be allocated
|
|
@return: mem_d
|
|
@return: mem_d
|
|
@date: 24/03/2011
|
|
@date: 24/03/2011
|
|
@@ -699,10 +710,10 @@ cl_mem _clMalloc(int size) throw(string){
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
oclHandles.error_str += "unknown reasons";
|
|
oclHandles.error_str += "unknown reasons";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
- }
|
|
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
#ifdef PROFILE_
|
|
#ifdef PROFILE_
|
|
double t2 = gettime();
|
|
double t2 = gettime();
|
|
@@ -745,14 +756,14 @@ void* _clMallocHost(int size)throw(string){
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
oclHandles.error_str += "unknown reasons";
|
|
oclHandles.error_str += "unknown reasons";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
- }
|
|
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
|
|
|
|
mem_h = clEnqueueMapBuffer(oclHandles.queue, oclHandles.pinned_mem_out, CL_TRUE, CL_MAP_READ, 0, size, 0, NULL, NULL, &oclHandles.cl_status);
|
|
mem_h = clEnqueueMapBuffer(oclHandles.queue, oclHandles.pinned_mem_out, CL_TRUE, CL_MAP_READ, 0, size, 0, NULL, NULL, &oclHandles.cl_status);
|
|
-
|
|
|
|
|
|
+
|
|
#ifdef ERRMSG
|
|
#ifdef ERRMSG
|
|
if(oclHandles.cl_status != CL_SUCCESS||mem_h==NULL){
|
|
if(oclHandles.cl_status != CL_SUCCESS||mem_h==NULL){
|
|
oclHandles.error_str = "excpetion in _clMallocHost -> clEnqueueMapBuffer";
|
|
oclHandles.error_str = "excpetion in _clMallocHost -> clEnqueueMapBuffer";
|
|
@@ -783,10 +794,10 @@ void* _clMallocHost(int size)throw(string){
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
oclHandles.error_str += "unknown reasons";
|
|
oclHandles.error_str += "unknown reasons";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
- }
|
|
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
return mem_h;
|
|
return mem_h;
|
|
}
|
|
}
|
|
@@ -826,7 +837,7 @@ void _clFreeHost(int io, void * mem_h){
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
oclHandles.error_str += "unknown reasons";
|
|
oclHandles.error_str += "unknown reasons";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
}
|
|
}
|
|
@@ -860,12 +871,12 @@ void _clFreeHost(int io, void * mem_h){
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
oclHandles.error_str += "unknown reasons";
|
|
oclHandles.error_str += "unknown reasons";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
throw(string("encounter invalid choice when freeing pinned memmory"));
|
|
throw(string("encounter invalid choice when freeing pinned memmory"));
|
|
@@ -874,7 +885,7 @@ void _clFreeHost(int io, void * mem_h){
|
|
@function: transfer data from host to device
|
|
@function: transfer data from host to device
|
|
@params:
|
|
@params:
|
|
dest: the destination device memory
|
|
dest: the destination device memory
|
|
- src: the source host memory
|
|
|
|
|
|
+ src: the source host memory
|
|
size: the size of data to be transferred in bytes
|
|
size: the size of data to be transferred in bytes
|
|
@return: NULL
|
|
@return: NULL
|
|
@date: 17/01/2011
|
|
@date: 17/01/2011
|
|
@@ -893,28 +904,28 @@ void _clMemcpyH2D(cl_mem dst, const void *src, int size) throw(string){
|
|
break;
|
|
break;
|
|
case CL_INVALID_CONTEXT:
|
|
case CL_INVALID_CONTEXT:
|
|
oclHandles.error_str += "CL_INVALID_CONTEXT";
|
|
oclHandles.error_str += "CL_INVALID_CONTEXT";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_MEM_OBJECT:
|
|
case CL_INVALID_MEM_OBJECT:
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
break;
|
|
break;
|
|
case CL_INVALID_VALUE:
|
|
case CL_INVALID_VALUE:
|
|
oclHandles.error_str += "CL_INVALID_VALUE";
|
|
oclHandles.error_str += "CL_INVALID_VALUE";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_EVENT_WAIT_LIST:
|
|
case CL_INVALID_EVENT_WAIT_LIST:
|
|
oclHandles.error_str += "CL_INVALID_EVENT_WAIT_LIST";
|
|
oclHandles.error_str += "CL_INVALID_EVENT_WAIT_LIST";
|
|
break;
|
|
break;
|
|
case CL_MEM_OBJECT_ALLOCATION_FAILURE:
|
|
case CL_MEM_OBJECT_ALLOCATION_FAILURE:
|
|
oclHandles.error_str += "CL_MEM_OBJECT_ALLOCATION_FAILURE";
|
|
oclHandles.error_str += "CL_MEM_OBJECT_ALLOCATION_FAILURE";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
oclHandles.error_str += "Unknown reason";
|
|
oclHandles.error_str += "Unknown reason";
|
|
break;
|
|
break;
|
|
- }
|
|
|
|
|
|
+ }
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
- }
|
|
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
#ifdef PROFILE_
|
|
#ifdef PROFILE_
|
|
double t2 = gettime();
|
|
double t2 = gettime();
|
|
@@ -926,7 +937,7 @@ void _clMemcpyH2D(cl_mem dst, const void *src, int size) throw(string){
|
|
@function: transfer data from device to host
|
|
@function: transfer data from device to host
|
|
@params:
|
|
@params:
|
|
dest: the destination device memory
|
|
dest: the destination device memory
|
|
- src: the source host memory
|
|
|
|
|
|
+ src: the source host memory
|
|
size: the size of data to be transferred in bytes
|
|
size: the size of data to be transferred in bytes
|
|
@return: NULL
|
|
@return: NULL
|
|
@date: 17/01/2011
|
|
@date: 17/01/2011
|
|
@@ -945,28 +956,28 @@ void _clMemcpyD2H(void * dst, cl_mem src, int size) throw(string){
|
|
break;
|
|
break;
|
|
case CL_INVALID_CONTEXT:
|
|
case CL_INVALID_CONTEXT:
|
|
oclHandles.error_str += "CL_INVALID_CONTEXT";
|
|
oclHandles.error_str += "CL_INVALID_CONTEXT";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_MEM_OBJECT:
|
|
case CL_INVALID_MEM_OBJECT:
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
break;
|
|
break;
|
|
case CL_INVALID_VALUE:
|
|
case CL_INVALID_VALUE:
|
|
oclHandles.error_str += "CL_INVALID_VALUE";
|
|
oclHandles.error_str += "CL_INVALID_VALUE";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_EVENT_WAIT_LIST:
|
|
case CL_INVALID_EVENT_WAIT_LIST:
|
|
oclHandles.error_str += "CL_INVALID_EVENT_WAIT_LIST";
|
|
oclHandles.error_str += "CL_INVALID_EVENT_WAIT_LIST";
|
|
break;
|
|
break;
|
|
case CL_MEM_OBJECT_ALLOCATION_FAILURE:
|
|
case CL_MEM_OBJECT_ALLOCATION_FAILURE:
|
|
oclHandles.error_str += "CL_MEM_OBJECT_ALLOCATION_FAILURE";
|
|
oclHandles.error_str += "CL_MEM_OBJECT_ALLOCATION_FAILURE";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
oclHandles.error_str += "Unknown reason";
|
|
oclHandles.error_str += "Unknown reason";
|
|
break;
|
|
break;
|
|
- }
|
|
|
|
|
|
+ }
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
- }
|
|
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
#ifdef PROFILE_
|
|
#ifdef PROFILE_
|
|
double t2 = gettime();
|
|
double t2 = gettime();
|
|
@@ -977,7 +988,7 @@ void _clMemcpyD2H(void * dst, cl_mem src, int size) throw(string){
|
|
@function: transfer data from device to device
|
|
@function: transfer data from device to device
|
|
@params:
|
|
@params:
|
|
dest: the destination device memory
|
|
dest: the destination device memory
|
|
- src: the source device memory
|
|
|
|
|
|
+ src: the source device memory
|
|
size: the size of data to be transferred in bytes
|
|
size: the size of data to be transferred in bytes
|
|
@return: NULL
|
|
@return: NULL
|
|
@date: 27/03/2011
|
|
@date: 27/03/2011
|
|
@@ -996,37 +1007,37 @@ void _clMemcpyD2D(cl_mem dst, cl_mem src, int size) throw(string){
|
|
break;
|
|
break;
|
|
case CL_INVALID_CONTEXT:
|
|
case CL_INVALID_CONTEXT:
|
|
oclHandles.error_str += "CL_INVALID_CONTEXT";
|
|
oclHandles.error_str += "CL_INVALID_CONTEXT";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_MEM_OBJECT:
|
|
case CL_INVALID_MEM_OBJECT:
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
break;
|
|
break;
|
|
case CL_INVALID_VALUE:
|
|
case CL_INVALID_VALUE:
|
|
oclHandles.error_str += "CL_INVALID_VALUE";
|
|
oclHandles.error_str += "CL_INVALID_VALUE";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_EVENT_WAIT_LIST:
|
|
case CL_INVALID_EVENT_WAIT_LIST:
|
|
oclHandles.error_str += "CL_INVALID_EVENT_WAIT_LIST";
|
|
oclHandles.error_str += "CL_INVALID_EVENT_WAIT_LIST";
|
|
break;
|
|
break;
|
|
case CL_MISALIGNED_SUB_BUFFER_OFFSET:
|
|
case CL_MISALIGNED_SUB_BUFFER_OFFSET:
|
|
oclHandles.error_str += "CL_MISALIGNED_SUB_BUFFER_OFFSET";
|
|
oclHandles.error_str += "CL_MISALIGNED_SUB_BUFFER_OFFSET";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_MEM_COPY_OVERLAP:
|
|
case CL_MEM_COPY_OVERLAP:
|
|
oclHandles.error_str += "CL_MEM_COPY_OVERLAP";
|
|
oclHandles.error_str += "CL_MEM_COPY_OVERLAP";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_MEM_OBJECT_ALLOCATION_FAILURE:
|
|
case CL_MEM_OBJECT_ALLOCATION_FAILURE:
|
|
oclHandles.error_str += "CL_MEM_OBJECT_ALLOCATION_FAILURE";
|
|
oclHandles.error_str += "CL_MEM_OBJECT_ALLOCATION_FAILURE";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_OUT_OF_RESOURCES:
|
|
case CL_OUT_OF_RESOURCES:
|
|
oclHandles.error_str += "CL_OUT_OF_RESOURCES";
|
|
oclHandles.error_str += "CL_OUT_OF_RESOURCES";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
oclHandles.error_str += "Unknown reason";
|
|
oclHandles.error_str += "Unknown reason";
|
|
break;
|
|
break;
|
|
- }
|
|
|
|
|
|
+ }
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
- }
|
|
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
#ifdef PROFILE_
|
|
#ifdef PROFILE_
|
|
double t2 = gettime();
|
|
double t2 = gettime();
|
|
@@ -1055,19 +1066,19 @@ void _clSetArgs(int kernel_id, int arg_idx, void * d_mem, int size = 0) throw(st
|
|
break;
|
|
break;
|
|
case CL_INVALID_ARG_INDEX:
|
|
case CL_INVALID_ARG_INDEX:
|
|
oclHandles.error_str += "CL_INVALID_ARG_INDEX";
|
|
oclHandles.error_str += "CL_INVALID_ARG_INDEX";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_ARG_VALUE:
|
|
case CL_INVALID_ARG_VALUE:
|
|
oclHandles.error_str += "CL_INVALID_ARG_VALUE";
|
|
oclHandles.error_str += "CL_INVALID_ARG_VALUE";
|
|
break;
|
|
break;
|
|
case CL_INVALID_MEM_OBJECT:
|
|
case CL_INVALID_MEM_OBJECT:
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_SAMPLER:
|
|
case CL_INVALID_SAMPLER:
|
|
oclHandles.error_str += "CL_INVALID_SAMPLER";
|
|
oclHandles.error_str += "CL_INVALID_SAMPLER";
|
|
break;
|
|
break;
|
|
case CL_INVALID_ARG_SIZE:
|
|
case CL_INVALID_ARG_SIZE:
|
|
oclHandles.error_str += "CL_INVALID_ARG_SIZE";
|
|
oclHandles.error_str += "CL_INVALID_ARG_SIZE";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_OUT_OF_RESOURCES:
|
|
case CL_OUT_OF_RESOURCES:
|
|
oclHandles.error_str += "CL_OUT_OF_RESOURCES";
|
|
oclHandles.error_str += "CL_OUT_OF_RESOURCES";
|
|
break;
|
|
break;
|
|
@@ -1092,19 +1103,19 @@ void _clSetArgs(int kernel_id, int arg_idx, void * d_mem, int size = 0) throw(st
|
|
break;
|
|
break;
|
|
case CL_INVALID_ARG_INDEX:
|
|
case CL_INVALID_ARG_INDEX:
|
|
oclHandles.error_str += "CL_INVALID_ARG_INDEX";
|
|
oclHandles.error_str += "CL_INVALID_ARG_INDEX";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_ARG_VALUE:
|
|
case CL_INVALID_ARG_VALUE:
|
|
oclHandles.error_str += "CL_INVALID_ARG_VALUE";
|
|
oclHandles.error_str += "CL_INVALID_ARG_VALUE";
|
|
break;
|
|
break;
|
|
case CL_INVALID_MEM_OBJECT:
|
|
case CL_INVALID_MEM_OBJECT:
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
oclHandles.error_str += "CL_INVALID_MEM_OBJECT";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_INVALID_SAMPLER:
|
|
case CL_INVALID_SAMPLER:
|
|
oclHandles.error_str += "CL_INVALID_SAMPLER";
|
|
oclHandles.error_str += "CL_INVALID_SAMPLER";
|
|
break;
|
|
break;
|
|
case CL_INVALID_ARG_SIZE:
|
|
case CL_INVALID_ARG_SIZE:
|
|
oclHandles.error_str += "CL_INVALID_ARG_SIZE";
|
|
oclHandles.error_str += "CL_INVALID_ARG_SIZE";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_OUT_OF_RESOURCES:
|
|
case CL_OUT_OF_RESOURCES:
|
|
oclHandles.error_str += "CL_OUT_OF_RESOURCES";
|
|
oclHandles.error_str += "CL_OUT_OF_RESOURCES";
|
|
break;
|
|
break;
|
|
@@ -1121,7 +1132,7 @@ void _clSetArgs(int kernel_id, int arg_idx, void * d_mem, int size = 0) throw(st
|
|
}
|
|
}
|
|
}
|
|
}
|
|
void _clFinish() throw(string){
|
|
void _clFinish() throw(string){
|
|
- oclHandles.cl_status = clFinish(oclHandles.queue);
|
|
|
|
|
|
+ oclHandles.cl_status = clFinish(oclHandles.queue);
|
|
#ifdef ERRMSG
|
|
#ifdef ERRMSG
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
if(oclHandles.cl_status!=CL_SUCCESS){
|
|
oclHandles.error_str = "excpetion in _clFinish";
|
|
oclHandles.error_str = "excpetion in _clFinish";
|
|
@@ -1131,7 +1142,7 @@ void _clFinish() throw(string){
|
|
break;
|
|
break;
|
|
case CL_OUT_OF_RESOURCES:
|
|
case CL_OUT_OF_RESOURCES:
|
|
oclHandles.error_str += "CL_OUT_OF_RESOURCES";
|
|
oclHandles.error_str += "CL_OUT_OF_RESOURCES";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
break;
|
|
break;
|
|
@@ -1163,7 +1174,7 @@ void _clInvokeKernel(int kernel_id, int work_items, int work_group_size) throw(s
|
|
size_t local_work_size[] = {work_group_size, 1};
|
|
size_t local_work_size[] = {work_group_size, 1};
|
|
size_t global_work_size[] = {work_items, 1};
|
|
size_t global_work_size[] = {work_items, 1};
|
|
oclHandles.cl_status = clEnqueueNDRangeKernel(oclHandles.queue, oclHandles.kernel[kernel_id], work_dim, 0, \
|
|
oclHandles.cl_status = clEnqueueNDRangeKernel(oclHandles.queue, oclHandles.kernel[kernel_id], work_dim, 0, \
|
|
- global_work_size, local_work_size, 0 , 0, &(e[0]) );
|
|
|
|
|
|
+ global_work_size, local_work_size, 0 , 0, &(e[0]) );
|
|
#ifdef ERRMSG
|
|
#ifdef ERRMSG
|
|
if(oclHandles.cl_status != CL_SUCCESS){
|
|
if(oclHandles.cl_status != CL_SUCCESS){
|
|
oclHandles.error_str = "excpetion in _clInvokeKernel() -> ";
|
|
oclHandles.error_str = "excpetion in _clInvokeKernel() -> ";
|
|
@@ -1210,12 +1221,12 @@ void _clInvokeKernel(int kernel_id, int work_items, int work_group_size) throw(s
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
break;
|
|
break;
|
|
- default:
|
|
|
|
|
|
+ default:
|
|
oclHandles.error_str += "Unkown reseason";
|
|
oclHandles.error_str += "Unkown reseason";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
-
|
|
|
|
- throw(oclHandles.error_str);
|
|
|
|
|
|
+
|
|
|
|
+ throw(oclHandles.error_str);
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
//_clFinish();
|
|
//_clFinish();
|
|
@@ -1257,7 +1268,7 @@ void _clInvokeKernel(int kernel_id, int work_items, int work_group_size) throw(s
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
/*------------------------------------------------------------
|
|
@function: set device memory in an easy manner
|
|
@function: set device memory in an easy manner
|
|
- @params:
|
|
|
|
|
|
+ @params:
|
|
mem_d: the device memory to be set;
|
|
mem_d: the device memory to be set;
|
|
val: set the selected memory to 'val';
|
|
val: set the selected memory to 'val';
|
|
number_elements: the number of elements in the selected memory
|
|
number_elements: the number of elements in the selected memory
|
|
@@ -1270,7 +1281,7 @@ void _clMemset(cl_mem mem_d, short val, int number_bytes)throw(string){
|
|
int arg_idx = 0;
|
|
int arg_idx = 0;
|
|
_clSetArgs(kernel_id, arg_idx++, mem_d);
|
|
_clSetArgs(kernel_id, arg_idx++, mem_d);
|
|
_clSetArgs(kernel_id, arg_idx++, &val, sizeof(short));
|
|
_clSetArgs(kernel_id, arg_idx++, &val, sizeof(short));
|
|
- _clSetArgs(kernel_id, arg_idx++, &number_bytes, sizeof(int));
|
|
|
|
|
|
+ _clSetArgs(kernel_id, arg_idx++, &number_bytes, sizeof(int));
|
|
_clInvokeKernel(kernel_id, number_bytes, work_group_size);
|
|
_clInvokeKernel(kernel_id, number_bytes, work_group_size);
|
|
}
|
|
}
|
|
/*------------------------------------------------------------
|
|
/*------------------------------------------------------------
|
|
@@ -1280,7 +1291,7 @@ void _clMemset(cl_mem mem_d, short val, int number_bytes)throw(string){
|
|
range_x: the number of working items in x direction
|
|
range_x: the number of working items in x direction
|
|
range_y: the number of working items in y direction
|
|
range_y: the number of working items in y direction
|
|
group_x: the number of working items in each work group in x direction
|
|
group_x: the number of working items in each work group in x direction
|
|
- group_y: the number of working items in each work group in y direction
|
|
|
|
|
|
+ group_y: the number of working items in each work group in y direction
|
|
@return: NULL
|
|
@return: NULL
|
|
@date: 03/04/2011
|
|
@date: 03/04/2011
|
|
------------------------------------------------------------*/
|
|
------------------------------------------------------------*/
|
|
@@ -1295,7 +1306,7 @@ void _clInvokeKernel2D(int kernel_id, int range_x, int range_y, int group_x, int
|
|
/*if(work_items%work_group_size != 0) //process situations that work_items cannot be divided by work_group_size
|
|
/*if(work_items%work_group_size != 0) //process situations that work_items cannot be divided by work_group_size
|
|
work_items = work_items + (work_group_size-(work_items%work_group_size));*/
|
|
work_items = work_items + (work_group_size-(work_items%work_group_size));*/
|
|
oclHandles.cl_status = clEnqueueNDRangeKernel(oclHandles.queue, oclHandles.kernel[kernel_id], work_dim, 0, \
|
|
oclHandles.cl_status = clEnqueueNDRangeKernel(oclHandles.queue, oclHandles.kernel[kernel_id], work_dim, 0, \
|
|
- global_work_size, local_work_size, 0 , 0, &(e[0]) );
|
|
|
|
|
|
+ global_work_size, local_work_size, 0 , 0, &(e[0]) );
|
|
#ifdef ERRMSG
|
|
#ifdef ERRMSG
|
|
if(oclHandles.cl_status != CL_SUCCESS){
|
|
if(oclHandles.cl_status != CL_SUCCESS){
|
|
oclHandles.error_str = "excpetion in _clInvokeKernel() -> ";
|
|
oclHandles.error_str = "excpetion in _clInvokeKernel() -> ";
|
|
@@ -1342,14 +1353,14 @@ void _clInvokeKernel2D(int kernel_id, int range_x, int range_y, int group_x, int
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
break;
|
|
break;
|
|
- default:
|
|
|
|
|
|
+ default:
|
|
oclHandles.error_str += "Unkown reseason";
|
|
oclHandles.error_str += "Unkown reseason";
|
|
- break;
|
|
|
|
- }
|
|
|
|
- throw(oclHandles.error_str);
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ throw(oclHandles.error_str);
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
-
|
|
|
|
|
|
+
|
|
// oclHandles.cl_status = clWaitForEvents(1, &e[0]);
|
|
// oclHandles.cl_status = clWaitForEvents(1, &e[0]);
|
|
|
|
|
|
#ifdef ERRMSG
|
|
#ifdef ERRMSG
|
|
@@ -1374,10 +1385,10 @@ void _clInvokeKernel2D(int kernel_id, int range_x, int range_y, int group_x, int
|
|
|
|
|
|
void _clFree(cl_mem ob) throw(string){
|
|
void _clFree(cl_mem ob) throw(string){
|
|
#ifdef PROFILE_
|
|
#ifdef PROFILE_
|
|
- double t1 = gettime();
|
|
|
|
|
|
+ double t1 = gettime();
|
|
#endif
|
|
#endif
|
|
if(ob!=NULL)
|
|
if(ob!=NULL)
|
|
- oclHandles.cl_status = clReleaseMemObject(ob);
|
|
|
|
|
|
+ oclHandles.cl_status = clReleaseMemObject(ob);
|
|
#ifdef ERRMSG
|
|
#ifdef ERRMSG
|
|
if (oclHandles.cl_status!= CL_SUCCESS){
|
|
if (oclHandles.cl_status!= CL_SUCCESS){
|
|
oclHandles.error_str = "excpetion in _clFree() ->";
|
|
oclHandles.error_str = "excpetion in _clFree() ->";
|
|
@@ -1390,10 +1401,10 @@ void _clFree(cl_mem ob) throw(string){
|
|
break;
|
|
break;
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
case CL_OUT_OF_HOST_MEMORY:
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
oclHandles.error_str += "CL_OUT_OF_HOST_MEMORY";
|
|
- break;
|
|
|
|
- default:
|
|
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
oclHandles.error_str += "Unkown reseason";
|
|
oclHandles.error_str += "Unkown reseason";
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
throw(oclHandles.error_str);
|
|
throw(oclHandles.error_str);
|
|
}
|
|
}
|
|
@@ -1415,7 +1426,7 @@ void _clStatistics(){
|
|
FILE *fp_pd = fopen("PD_OCL.txt", "a");
|
|
FILE *fp_pd = fopen("PD_OCL.txt", "a");
|
|
fprintf(fp_pd, "%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf\n", CC, CR, MA, MF, H2D, D2H, D2D, KE, KC);
|
|
fprintf(fp_pd, "%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf\n", CC, CR, MA, MF, H2D, D2H, D2D, KE, KC);
|
|
fclose(fp_pd);
|
|
fclose(fp_pd);
|
|
-#endif
|
|
|
|
|
|
+#endif
|
|
return ;
|
|
return ;
|
|
}
|
|
}
|
|
#endif //_CL_HELPER_
|
|
#endif //_CL_HELPER_
|