Ejemplo n.º 1
0
void capture(const EdsCameraRef handle, \
			const double isoSpeedDouble, const double apertureValueDouble, \
			const double shutterSpeedDouble) {

	EdsError errorCode = EDS_ERR_OK;

	EdsUInt32 isoSpeed = isoSpeedDoubleToEds(isoSpeedDouble);
	errorCode = EdsSetPropertyData(handle, kEdsPropID_ISOSpeed, 0,
								sizeof(isoSpeed), &isoSpeed);
	if (errorCode != EDS_ERR_OK) {
		handleErrorCode(errorCode);
	}

	EdsUInt32 apertureValue = apertureValueDoubleToEds(apertureValueDouble);
	errorCode = EdsSetPropertyData(handle, kEdsPropID_Av, 0,
								sizeof(apertureValue), &apertureValue);
	if (errorCode != EDS_ERR_OK) {
		handleErrorCode(errorCode);
	}

	EdsUInt32 shutterSpeed = shutterSpeedDoubleToEds(shutterSpeedDouble);
	errorCode = EdsSetPropertyData(handle, kEdsPropID_Tv, 0,
								sizeof(shutterSpeed), &shutterSpeed);
	if (errorCode != EDS_ERR_OK) {
		handleErrorCode(errorCode);
	}

	snap(handle);
}
Ejemplo n.º 2
0
void pressShutter(const EdsCameraRef handle) {
	EdsError errorCode = EdsSendCommand(handle,
										kEdsCameraCommand_PressShutterButton,
										kEdsCameraCommand_ShutterButton_Completely_NonAF);
	if (errorCode != EDS_ERR_OK) {
		handleErrorCode(errorCode);
	}
}
Ejemplo n.º 3
0
void releaseShutter(const EdsCameraRef handle) {
	EdsError errorCode = EdsSendCommand(handle,
										kEdsCameraCommand_PressShutterButton,
										kEdsCameraCommand_ShutterButton_OFF);
	if (errorCode != EDS_ERR_OK) {
		handleErrorCode(errorCode);
	}
}
Ejemplo n.º 4
0
void closeCamera(EdsCameraRef handle) {
	EdsError err = EdsCloseSession(handle);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Release camera
	if (handle != NULL) {
		EdsRelease(handle);
	}
}
Ejemplo n.º 5
0
 void handleHandshake(const boost::system::error_code& ec)
 {
    try
    {
       if (!ec)
       {
          // finished handshake, commence with request
          writeRequest();
       }
       else
       {
          handleErrorCode(ec, ERROR_LOCATION);
       }
    }
    CATCH_UNEXPECTED_ASYNC_CLIENT_EXCEPTION
 }
Ejemplo n.º 6
0
unsigned queryCamera() {

	EdsCameraListRef cameraList = NULL;
	EdsError err = EdsGetCameraList(&cameraList);
	if (err != EDS_ERR_OK) {
	}

	EdsUInt32 numCameras = 0;
	err = EdsGetChildCount(cameraList, &numCameras);
	if (err == EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Release camera list
	if (cameraList != NULL) {
		EdsRelease(cameraList);
		cameraList = NULL;
	}

	return (unsigned) numCameras;
}
Ejemplo n.º 7
0
void snap(const EdsCameraRef handle) {
	EdsError errorCode = EdsSendCommand(handle, kEdsCameraCommand_TakePicture, 0);
	if (errorCode != EDS_ERR_OK) {
		handleErrorCode(errorCode);
	}
}
Ejemplo n.º 8
0
EdsCameraRef openCamera() {
	EdsCameraListRef cameraList = NULL;
	// Get camera list
	EdsError err = EdsGetCameraList(&cameraList);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	EdsUInt32 numCameras = 0;
	// Get number of cameras
	err = EdsGetChildCount(cameraList, &numCameras);
	if (err == EDS_ERR_OK) {
		handleErrorCode(err);
	}

	if (numCameras > 1) {
		mexWarnMsgTxt("Warning: more than one available cameras found. Multiple cameras are not well supported.");
	} else if (numCameras <= 0) {
		mexErrMsgIdAndTxt(ERROR_ID, "No available camera found.");
		return NULL;
	}

	EdsCameraRef handle;
	// Get first camera retrieved
	err = EdsGetChildAtIndex(cameraList , 0 , &handle);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Release camera list
	if (cameraList != NULL) {
		EdsRelease(cameraList);
		cameraList = NULL;
	}

	// Set object event handler
	err = EdsSetObjectEventHandler(handle, kEdsObjectEvent_All, handleObjectEvent, NULL);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Set property event handler
	err = EdsSetPropertyEventHandler(handle, kEdsPropertyEvent_All, handlePropertyEvent, NULL);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Set camera state event handler
	err = EdsSetCameraStateEventHandler(handle, kEdsStateEvent_All, handleStateEvent, NULL);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Open session with camera
	err = EdsOpenSession(handle);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	return handle;
}
Ejemplo n.º 9
0
void SQLiteStatement::bind( co::uint32 index, const char* value, int bytes )
{
	handleErrorCode( sqlite3_bind_text( _stmt, index, value, bytes, SQLITE_TRANSIENT ));
}
Ejemplo n.º 10
0
void initializeSDK() {
	EdsError err = EdsInitializeSDK();
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}
}
Ejemplo n.º 11
0
void setCameraProperty(const EdsCameraRef handle, \
							const CAMERA_PROPERTY property, \
							const mxArray* mxarr) {

	switch(property) {
		case CAMERA_AEMODE: {
			EdsUInt32 AEMode = AEModeDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_AEMode, 0,
													sizeof(AEMode),
													&AEMode);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_DRIVEMODE: {
			EdsUInt32 driveMode = driveModeDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_DriveMode, 0,
													sizeof(driveMode),
													&driveMode);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_IMAGEQUALITY: {
			EdsUInt32 imageQuality = imageQualityDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_ImageQuality, 0,
													sizeof(imageQuality),
													&imageQuality);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_ISOSPEED: {
			EdsUInt32 isoSpeed = isoSpeedDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_ISOSpeed, 0,
													sizeof(isoSpeed),
													&isoSpeed);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_APERTUREVALUE: {
			EdsUInt32 apertureValue = apertureValueDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Av, 0,
													sizeof(apertureValue),
													&apertureValue);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_SHUTTERSPEED: {
			EdsUInt32 shutterSpeed = shutterSpeedDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Tv, 0,
													sizeof(shutterSpeed),
													&shutterSpeed);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_EVFOUTPUTDEVICE: {
			EdsUInt32 evfOutputDevice = evfOutputDeviceDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Evf_OutputDevice, 0,
													sizeof(evfOutputDevice),
													&evfOutputDevice);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_EVFMODE: {
			EdsUInt32 evfMode = evfModeDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Evf_Mode, 0,
													sizeof(evfMode),
													&evfMode);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		case CAMERA_SAVETO: {
			EdsUInt32 saveTo = saveToDoubleToEds(mxGetScalar(mxarr));
			EdsError errorCode = EdsSetPropertyData(handle,
													kEdsPropID_Evf_Mode, 0,
													sizeof(saveTo),
													&saveTo);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			break;
		}
		default:
		{
			char propertyName[canon_MAX_STRING_LENGTH];
			cameraPropertyToString(property, propertyName);
			mexErrMsgIdAndTxt(ERROR_ID, "Unknown or unsupported camera property: %s.", propertyName);
		}
	}
}
Ejemplo n.º 12
0
mxArray* getCameraProperty(const EdsCameraRef handle, \
							const CAMERA_PROPERTY property) {

	switch(property) {
	case CAMERA_AEMODE: {
			EdsUInt32 AEMode;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_AEMode, 0,
													sizeof(AEMode),
													&AEMode);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(AEModeEdsToDouble(AEMode));
			return mxarr;
		}
		case CAMERA_DRIVEMODE: {
			EdsUInt32 driveMode;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_DriveMode, 0,
													sizeof(driveMode),
													&driveMode);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(driveModeEdsToDouble(driveMode));
			return mxarr;
		}
		case CAMERA_IMAGEQUALITY: {
			EdsUInt32 imageQuality;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_ImageQuality, 0,
													sizeof(imageQuality),
													&imageQuality);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(imageQualityEdsToDouble(imageQuality));
			return mxarr;
		}
		case CAMERA_ISOSPEED: {
			EdsUInt32 isoSpeed;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_ISOSpeed, 0,
													sizeof(isoSpeed),
													&isoSpeed);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(isoSpeedEdsToDouble(isoSpeed));
			return mxarr;
		}
		case CAMERA_APERTUREVALUE: {
			EdsUInt32 apertureValue;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_Av, 0,
													sizeof(apertureValue),
													&apertureValue);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(apertureValueEdsToDouble(apertureValue));
			return mxarr;
		}
		case CAMERA_SHUTTERSPEED: {
			EdsUInt32 shutterSpeed;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_Tv, 0,
													sizeof(shutterSpeed),
													&shutterSpeed);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(shutterSpeedEdsToDouble(shutterSpeed));
			return mxarr;
		}
		case CAMERA_EVFOUTPUTDEVICE: {
			EdsUInt32 evfOutputDevice;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_Evf_OutputDevice, 0,
													sizeof(evfOutputDevice),
													&evfOutputDevice);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(evfOutputDeviceEdsToDouble(evfOutputDevice));
			return mxarr;
		}
		case CAMERA_EVFMODE: {
			EdsUInt32 evfMode;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_Evf_Mode, 0,
													sizeof(evfMode),
													&evfMode);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(evfModeEdsToDouble(evfMode));
			return mxarr;
		}
		case CAMERA_SAVETO: {
			EdsUInt32 saveTo;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_SaveTo, 0,
													sizeof(saveTo),
													&saveTo);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(saveToEdsToDouble(saveTo));
			return mxarr;
		}
		case CAMERA_AVAILABLESHOTS: {
			EdsUInt32 availableShots;
			EdsError errorCode = EdsGetPropertyData(handle,
													kEdsPropID_AvailableShots, 0,
													sizeof(availableShots),
													&availableShots);
			if (errorCode != EDS_ERR_OK) {
				handleErrorCode(errorCode);
			}
			mxArray *mxarr = mxCreateDoubleScalar(availableShotsEdsToDouble(availableShots));
			return mxarr;
		}
		default: {
			char propertyName[canon_MAX_STRING_LENGTH];
			cameraPropertyToString(property, propertyName);
			mexErrMsgIdAndTxt(ERROR_ID, "Unknown or unsupported camera property: %s.", propertyName);
			return NULL;
		}
	}
}
Ejemplo n.º 13
0
void SQLiteStatement::bindDouble( co::uint32 index, double value )
{
	handleErrorCode( sqlite3_bind_double( _stmt, index, value ));
}
Ejemplo n.º 14
0
void SQLiteStatement::bind( co::uint32 index, co::int32 value )
{
	handleErrorCode( sqlite3_bind_int( _stmt, index, value ) );
}
Ejemplo n.º 15
0
void SQLiteStatement::execute()
{
	handleErrorCode( sqlite3_step( _stmt ) );
}
Ejemplo n.º 16
0
void terminateSDK() {
	EdsError err = EdsTerminateSDK();
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}
}
Ejemplo n.º 17
0
int solve_ocl(problem* problem) {

	// -------------- create list of sub-problems ---------------------

	// get upper boundary for number of sub-problems
	int max_problems = powl(problem->size, OMP_CUT);

	// create array of activation records
	call_record* sub_problems = malloc(sizeof(call_record) * max_problems);
	call_record* pos = sub_problems;

	// create store for partial solutions
	int* block = malloc(sizeof(int) * max_problems * problem->size);
	int used = 0;

	// fill up sub-problem array
	volatile int best = 1<<30;
	int partial[problem->size];
	initActivationRecord(problem, partial, 0, 0, 0, &best, &pos, block, &used, OMP_CUT);

	unsigned num_sub_problems = pos - sub_problems;
	printf("Sub-problem list filled %d/%d\n", num_sub_problems, max_problems);


	// -------------- process list using GPU ---------------------

	// ---- process in parallel ----
	cl_int error;	

	// get platform
	cl_platform_id platform;
	{
		cl_uint numPlatforms;
		handleErrorCode(clGetPlatformIDs(0,0, &numPlatforms));
		INFO("Found %d platform(s)!", numPlatforms);

		cl_platform_id ids[numPlatforms];
		handleErrorCode(clGetPlatformIDs(numPlatforms,ids, &numPlatforms));

		platform = ids[0];
	}

	// get devices
	cl_device_id device;
	{
		cl_uint numDevices;
		handleErrorCode(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, 0, &numDevices));
		cl_device_id ids[numDevices];
		handleErrorCode(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, numDevices, ids, &numDevices));
		device = ids[0];

		size_t size;
		clGetDeviceInfo(device, CL_DEVICE_VENDOR, 0, 0, &size);
		char name[size];
		clGetDeviceInfo(device, CL_DEVICE_VENDOR, size*sizeof(char), name, 0); 
		printf("Using Device %s\n", name);
	}

	// create context
	INFO("Creating context ..");
	cl_context context = clCreateContext(0, 1, &device, 0, 0, &error);
	handleErrorCode(error);

	// create queue
	INFO("Creating command queue ..");
	cl_command_queue queue = clCreateCommandQueue(context, device, 0, &error);
	handleErrorCode(error);

	// create program
	INFO("Building program ..");
	cl_program program;
	{
		const char* code = loadFile("qap_array.cl");
		INFO("Kernel Code:\n%s\n", code);

		size_t code_length = strlen(code);
		program = clCreateProgramWithSource(context,1, &code, &code_length, &error);
		handleErrorCode(error);

		// build program
		error = clBuildProgram(program, 1, &device, 0, 0, 0);

		if (error == CL_BUILD_PROGRAM_FAILURE) {
			printf("Program built failed!\n");

			// obtain additional build error information
			size_t logSize = 2048;
			char log[logSize];
			clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, logSize, log, &logSize);

			printf("Log:\n%s\n", log);
				
			exit(1);
		} else {
			handleErrorCode(error);
		}
	}

	// get kernel
	INFO("Building kernel ..");
	cl_kernel kernel = clCreateKernel(program, "qap", &error);
	handleErrorCode(error);

	// create buffers
	INFO("Creating Buffers ..");
	cl_mem mA = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int)*problem->size*problem->size, problem->A->data, &error); handleErrorCode(error);
	cl_mem mB = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int)*problem->size*problem->size, problem->B->data, &error); handleErrorCode(error);
	cl_mem vC = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(call_record)*num_sub_problems, sub_problems, &error); handleErrorCode(error);
	cl_mem vP = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int)*problem->size*num_sub_problems, block, &error); handleErrorCode(error);
	cl_mem sR = clCreateBuffer(context, CL_MEM_READ_WRITE| CL_MEM_COPY_HOST_PTR, sizeof(int), (void*)&best, &error); handleErrorCode(error);

	// set up arguments
	INFO("Setting up Arguments ..");
	handleErrorCode(clSetKernelArg(kernel, 0, sizeof(int), &problem->size));
	handleErrorCode(clSetKernelArg(kernel, 1, sizeof(mA), &mA));
	handleErrorCode(clSetKernelArg(kernel, 2, sizeof(mB), &mB));
	handleErrorCode(clSetKernelArg(kernel, 3, sizeof(vC), &vC));
	handleErrorCode(clSetKernelArg(kernel, 4, sizeof(vP), &vP));
	handleErrorCode(clSetKernelArg(kernel, 5, sizeof(sR), &sR));
	handleErrorCode(clSetKernelArg(kernel, 6, sizeof(num_sub_problems), &num_sub_problems));

	// run kernel
	INFO("Running kernel ..");
	size_t local_work_size = 64;
	size_t global_work_offset = 0;
	size_t global_work_size = (num_sub_problems + (local_work_size - 1))/local_work_size*local_work_size;
	cl_event kernel_done;
	double start = getTime();
	handleErrorCode(clEnqueueNDRangeKernel(queue, kernel, 1, &global_work_offset, &global_work_size, &local_work_size, 0, 0, &kernel_done));

	handleErrorCode(clWaitForEvents(1,&kernel_done));
	double time = getTime() - start;
	printf("OpenCL Computation Time: %lf sec\n", time);

	// enqueue read operation
	cl_event read_done;
	int res = 0;
	handleErrorCode(clEnqueueReadBuffer(queue, sR, true, 0, sizeof(int), &res, 1, &kernel_done, &read_done));

	// wait for completion
	handleErrorCode(clWaitForEvents(1,&read_done));

	// cleanup
	handleErrorCode(clFinish(queue));
	handleErrorCode(clReleaseKernel(kernel));
	handleErrorCode(clReleaseProgram(program));
	handleErrorCode(clReleaseCommandQueue(queue));
	handleErrorCode(clReleaseContext(context));

	// -------------- free resources and be done ---------------------

	// free temporary arrays
	free(sub_problems);
	free(block);

	// return result
	return res;

/*

	// ---- process in parallel ----
	cl_int error;	

	// get platform
	cl_platform_id platform;
	{
		cl_uint numPlatforms;
		handleErrorCode(clGetPlatformIDs(0,0, &numPlatforms));
		INFO("Found %d platform(s)!", numPlatforms);

		cl_platform_id ids[numPlatforms];
		handleErrorCode(clGetPlatformIDs(numPlatforms,ids, &numPlatforms));

		platform = ids[0];
	}

	// get devices
	cl_device_id device;
	{
		cl_uint numDevices;
		handleErrorCode(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, 0, &numDevices));
		cl_device_id ids[numDevices];
		handleErrorCode(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, numDevices, ids, &numDevices));
		device = ids[0];
	}

	// create context
	INFO("Creating context ..");
	cl_context context = clCreateContext(0, 1, &device, 0, 0, &error);
	handleErrorCode(error);

	// create queue
	INFO("Creating command queue ..");
	cl_command_queue queue = clCreateCommandQueue(context, device, 0, &error);
	handleErrorCode(error);

	// create program
	INFO("Building program ..");
	cl_program program;
	{
		const char* code = loadFile("fib.cl");
		INFO("Kernel Code:\n%s\n", code);

		size_t code_length = strlen(code);
		program = clCreateProgramWithSource(context,1, &code, &code_length, &error);
		handleErrorCode(error);

		// build program
		error = clBuildProgram(program, 1, &device, 0, 0, 0);

		if (error == CL_BUILD_PROGRAM_FAILURE) {
			printf("Program built failed!\n");

			// obtain additional build error information
			size_t logSize = 2048;
			char log[logSize];
			clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, logSize, log, &logSize);

			printf("Log:\n%s\n", log);
				
			exit(1);
		} else {
			handleErrorCode(error);
		}
	}

	// get kernel
	INFO("Building kernel ..");
	cl_kernel kernel = clCreateKernel(program, "fib", &error);
	handleErrorCode(error);

	// create buffers
	INFO("Creating Buffers ..");
	cl_mem vecA = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int)*size, record, &error); handleErrorCode(error);
	cl_mem vecR = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(int)*size, 0, &error); handleErrorCode(error);

	// set up arguments
	INFO("Setting up Arguments ..");
	handleErrorCode(clSetKernelArg(kernel, 0, sizeof(vecA), &vecA));
	handleErrorCode(clSetKernelArg(kernel, 1, sizeof(vecR), &vecR));
	handleErrorCode(clSetKernelArg(kernel, 2, sizeof(size), &size));

	// run kernel
	INFO("Running kernel ..");
	size_t local_work_size = 64;
	size_t global_work_offset = 0;
	size_t global_work_size = size;
	cl_event kernel_done;
	double start = getTime();
	handleErrorCode(clEnqueueNDRangeKernel(queue, kernel, 1, &global_work_offset, &global_work_size, &local_work_size, 0, 0, &kernel_done));

	handleErrorCode(clWaitForEvents(1,&kernel_done));
	double time = getTime() - start;
	printf("OpenCL Computation Time: %lf sec\n", time);

	// enqueue read operation
	cl_event read_done;
	int* res = malloc(sizeof(int)*size);
	handleErrorCode(clEnqueueReadBuffer(queue, vecR, true, 0, sizeof(int)*size, res, 1, &kernel_done, &read_done));

	// wait for completion
	handleErrorCode(clWaitForEvents(1,&read_done));

	// cleanup
	handleErrorCode(clFinish(queue));
	handleErrorCode(clReleaseKernel(kernel));
	handleErrorCode(clReleaseProgram(program));
	handleErrorCode(clReleaseCommandQueue(queue));
	handleErrorCode(clReleaseContext(context));

	// aggregate results	TODO: move reduction to OpenCL kernel
	int sum = 0;
	#pragma omp parallel for reduction(+:sum)
	for(int i=0; i<size; i++) {
		sum += res[i];
	}

	// release arrays
	free(record);
	free(res);

	// done
	return sum;
*/
}
Ejemplo n.º 18
0
void SQLiteStatement::bind( co::uint32 index, const char* value )
{
	handleErrorCode( sqlite3_bind_text( _stmt, index, value, -1, NULL ));
}