// returns // - 0 if success // - ERR_FOPEN if init_data.xml missing // - ERR_XML_PARSE if can't parse init_data.xml // - ERR_NOT_FOUND if missing <gpu_type> or <gpu_device_num> fields // - an OpenCL error number if OpenCL error // int boinc_get_opencl_ids(cl_device_id* device, cl_platform_id* platform) { int retval; APP_INIT_DATA aid; int opencl_device_index; retval = boinc_parse_init_data_file(); if (retval) return retval; boinc_get_init_data(aid); if (!strlen(aid.gpu_type)) { fprintf(stderr, "GPU type not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } opencl_device_index = aid.gpu_opencl_dev_index; if (opencl_device_index < 0) { // Older versions of init_data.xml don't have gpu_opencl_dev_index field opencl_device_index = aid.gpu_device_num; } if (opencl_device_index < 0) { fprintf(stderr, "GPU device # not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } retval = boinc_get_opencl_ids_aux( aid.gpu_type, opencl_device_index, device, platform ); return retval; }
// Deprecated: use the version above instead // // returns // - 0 if success // - ERR_FOPEN if init_data.xml missing // - ERR_XML_PARSE if can't parse init_data.xml // - ERR_NOT_FOUND if missing <gpu_type> or <gpu_device_num> fields // - an OpenCL error number if OpenCL error // int boinc_get_opencl_ids(cl_device_id* device, cl_platform_id* platform) { int retval; APP_INIT_DATA aid; retval = boinc_parse_init_data_file(); if (retval) return retval; boinc_get_init_data(aid); if (!strlen(aid.gpu_type)) { fprintf(stderr, "GPU type not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } if ((aid.gpu_opencl_dev_index < 0) && (aid.gpu_device_num < 0)) { fprintf(stderr, "GPU device # not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } retval = boinc_get_opencl_ids_aux( aid.gpu_type, aid.gpu_opencl_dev_index, aid.gpu_device_num, device, platform ); return retval; }
// This version is compatible with older clients. // Usage: // Pass the argc and argv received from the BOINC client // type: may be PROC_TYPE_NVIDIA_GPU, PROC_TYPE_AMD_GPU or PROC_TYPE_INTEL_GPU // (it may also be 0, but then it will fail on older clients.) // // The argc, argv and type arguments are ignored for 7.0.12 or later clients. // // returns // - 0 if success // - ERR_FOPEN if init_data.xml missing // - ERR_XML_PARSE if can't parse init_data.xml // - CL_INVALID_DEVICE_TYPE if unable to get gpu_type information // - ERR_NOT_FOUND if unable to get opencl_device_index or gpu device_num // - an OpenCL error number if OpenCL error // int boinc_get_opencl_ids( int argc, char** argv, int type, cl_device_id* device, cl_platform_id* platform ){ int retval; APP_INIT_DATA aid; char *gpu_type = NULL; int gpu_device_num = -1; int i; retval = boinc_parse_init_data_file(); if (retval) return retval; boinc_get_init_data(aid); if (strlen(aid.gpu_type)) { gpu_type = aid.gpu_type; } else { switch (type) { case PROC_TYPE_NVIDIA_GPU: gpu_type = (char *)GPU_TYPE_NVIDIA; break; case PROC_TYPE_AMD_GPU: gpu_type = (char *)GPU_TYPE_ATI; break; case PROC_TYPE_INTEL_GPU: gpu_type = (char *)GPU_TYPE_INTEL; break; } } if ((!gpu_type) || !strlen(gpu_type)) { fprintf(stderr, "GPU type not found in %s\n", INIT_DATA_FILE); return CL_INVALID_DEVICE_TYPE; } if (aid.gpu_opencl_dev_index < 0) { // Older versions of init_data.xml don't have gpu_opencl_dev_index field // gpu_device_num = aid.gpu_device_num; if (gpu_device_num < 0) { // Even older versions of init_data.xml don't have gpu_device_num field for (i=0; i<argc-1; i++) { if ((!strcmp(argv[i], "--device")) || (!strcmp(argv[i], "-device"))) { gpu_device_num = atoi(argv[i+1]); break; } } } } if ((aid.gpu_opencl_dev_index < 0) && (gpu_device_num < 0)) { fprintf(stderr, "GPU device # not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } retval = boinc_get_opencl_ids_aux( gpu_type, aid.gpu_opencl_dev_index, gpu_device_num, device, platform ); return retval; }