|
@@ -216,7 +216,9 @@ string FileToString(const string fileName){
|
|
|
@date: 24/03/2011
|
|
|
------------------------------------------------------------*/
|
|
|
char device_type[3];
|
|
|
-int device_id = 0;
|
|
|
+static int platform_idx;
|
|
|
+static int device_idx = 0;
|
|
|
+
|
|
|
void _clCmdParams(int argc, char* argv[]){
|
|
|
for (int i = 0; i < argc; ++i){
|
|
|
switch (argv[i][1]){
|
|
@@ -229,15 +231,24 @@ void _clCmdParams(int argc, char* argv[]){
|
|
|
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': //--p stands for platform id
|
|
|
+ if (++i < argc){
|
|
|
+ sscanf(argv[i], "%d", &platform_idx);
|
|
|
+ }
|
|
|
+ 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_idx);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ std::cerr << "Could not read argument after option " << argv[i-1] << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
;
|
|
|
}
|
|
@@ -260,7 +271,7 @@ void _clCmdParams(int argc, char* argv[]){
|
|
|
get the number of devices and devices have no relationship with context
|
|
|
@date: 24/03/2011
|
|
|
------------------------------------------------------------*/
|
|
|
-void _clInit(string device_type, int device_id)throw(string){
|
|
|
+void _clInit(int platform_idx, int device_idx, string device_type)throw(string){
|
|
|
|
|
|
#ifdef PROFILE_
|
|
|
TE = 0;
|
|
@@ -310,8 +321,9 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
|
if (resultCL != CL_SUCCESS)
|
|
|
throw (string("InitCL()::Error: Getting platform ids (clGetPlatformIDs)"));
|
|
|
|
|
|
- // Select the target platform. Default: first platform
|
|
|
- targetPlatform = allPlatforms[1];
|
|
|
+ // Select the target platform.
|
|
|
+ printf("DEBUG %d \n", platform_idx);
|
|
|
+ targetPlatform = allPlatforms[platform_idx];
|
|
|
for (int i = 0; i < numPlatforms; i++)
|
|
|
{
|
|
|
char pbuff[128];
|
|
@@ -401,10 +413,10 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
|
throw(string("exception in _clInit -> clGetDeviceIDs -> ALL -> 2"));
|
|
|
}
|
|
|
}
|
|
|
- if(device_id!=0){
|
|
|
- if(device_id>(deviceListSize-1))
|
|
|
+ if(device_idx!=0){
|
|
|
+ if(device_idx>(deviceListSize-1))
|
|
|
throw(string("Invalidate device id"));
|
|
|
- DEVICE_ID_INUSED = device_id;
|
|
|
+ DEVICE_ID_INUSED = device_idx;
|
|
|
}
|
|
|
|
|
|
_clGetDeviceProperties(DEVICE_ID_INUSED, &prop);
|
|
@@ -419,16 +431,14 @@ void _clInit(string device_type, int device_id)throw(string){
|
|
|
#ifdef DEV_INFO
|
|
|
std::cout<<"--cambine: before creating context"<<std::endl;
|
|
|
#endif
|
|
|
+
|
|
|
+ cl_device_type device_type_cl = (device_type == "gpu") ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;
|
|
|
cl_context_properties cprops[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)targetPlatform, 0 };
|
|
|
- oclHandles.context = clCreateContext(0,
|
|
|
- deviceListSize,
|
|
|
- oclHandles.devices,
|
|
|
- NULL,
|
|
|
- NULL,
|
|
|
- &resultCL);
|
|
|
-
|
|
|
- if ((resultCL != CL_SUCCESS) || (oclHandles.context == NULL))
|
|
|
- throw (string("InitCL()::Error: Creating Context (clCreateContextFromType)"));
|
|
|
+ oclHandles.context = clCreateContextFromType(cprops, device_type_cl, NULL, NULL, NULL);
|
|
|
+ if (!oclHandles.context) {
|
|
|
+ printf("ERROR: clCreateContextFromType failed\n");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
#ifdef DEV_INFO
|
|
|
std::cout<<"--cambine: create OCL context successfully!"<<std::endl;
|
|
|
#endif
|