/* dpoIPlatform getPlatform (); */
NS_IMETHODIMP dpoCInterface::GetPlatform(dpoIPlatform **_retval)
{
	nsresult result = NS_OK;
	cl_int err_code;
	nsCOMPtr<dpoCPlatform> thePlatform;
	const cl_uint maxNameLength = 256;
	char name[maxNameLength];
	
	if (platforms == NULL) {
		result = InitPlatformInfo();
	}

	if (result != NS_OK) 
		return result;
		
	for (cl_uint i = 0; i < noOfPlatforms; i++) {
		err_code = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, maxNameLength*sizeof(char), name, NULL);
		if (err_code != CL_SUCCESS) {
			DEBUG_LOG_ERROR( "GetIntelPlatform", err_code);
			return NS_ERROR_NOT_AVAILABLE;
		}
		if ((strcmp(name, "Intel(R) OpenCL") == 0) || (strcmp(name, "Apple") == 0)) {
			thePlatform = new dpoCPlatform(this, platforms[i]);		
			if (thePlatform == NULL) {
				return NS_ERROR_OUT_OF_MEMORY;
			} else {
				thePlatform.forget((dpoCPlatform **) _retval);
				return NS_OK;
			}
		}
	}

	return NS_ERROR_NOT_AVAILABLE;
}
Beispiel #2
0
//
///* IPlatform getPlatform (); */
//
v8::Handle<v8::Value> CInterface::getPlatform(CPlatform* out)
{
	int result = CL_SUCCESS;
	cl_int err_code;
	const cl_uint maxNameLength = 256;
	char name[maxNameLength];
	
	if (platforms == NULL) {
		result = InitPlatformInfo();
	}

	if (result != CL_SUCCESS) 
		return v8::Undefined();
		
	for (cl_uint i = 0; i < noOfPlatforms; i++) {
		err_code = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, maxNameLength*sizeof(char), name, NULL);
		if (err_code != CL_SUCCESS) {
			DEBUG_LOG_ERROR( "GetIntelPlatform", err_code);
			return v8::Undefined();
		}
		if ((strcmp(name, "Intel(R) OpenCL") == 0) || (strcmp(name, "Apple") == 0)) {
			out = new CPlatform( platforms[i]);		
			if (out == NULL) {
				return v8::Undefined();
			} else {
				return CPlatform::toV8Object(out);
			}
		}
	}
	return  v8::Undefined();
}