int main(int argc, char* argv[]) { N = atol(argv[1]); A = (float*)malloc(N*N*sizeof(float)); B = (float*)malloc(N*N*sizeof(float)); C = (float*)malloc(N*N*sizeof(float)); seqOutput = (float*)malloc(N*N*sizeof(float)); init(A, B, C); seqGemm(); cl_platform_id* clPlatformIDs; cl_uint numPlatforms; cl_device_id* clDeviceIDs; cl_uint numDevices; cl_int err; pthread_t threads[10]; int ret; err = clGetPlatformIDs (0, NULL, &numPlatforms); printf("\n\033[0;37m%d Platforms Found: ", numPlatforms); clPlatformIDs = (cl_platform_id*)malloc(numPlatforms * sizeof(cl_platform_id)); err = clGetPlatformIDs (numPlatforms, clPlatformIDs, NULL); for(int i=0; i<numPlatforms; i++){ char stringOfPlatform[1024]; err = clGetPlatformInfo(clPlatformIDs[i], CL_PLATFORM_NAME, sizeof(stringOfPlatform), &stringOfPlatform, NULL); printf("\033[0;31mPlatforms[%d]\033[0;37m: %s\n", i, stringOfPlatform); err = clGetDeviceIDs (clPlatformIDs[i], CL_DEVICE_TYPE_ALL, 0, NULL, &numDevices); printf("(%d Devices Found in Platforms[%d])\n\n", numDevices, i); clDeviceIDs = (cl_device_id*)malloc(numDevices * sizeof(cl_device_id)); err = clGetDeviceIDs (clPlatformIDs[i], CL_DEVICE_TYPE_ALL, numDevices, clDeviceIDs, &numDevices); for(int j = 0; j < numDevices; j++ ){ char stringOfDevice[1024]; err = clGetDeviceInfo(clDeviceIDs[j], CL_DEVICE_NAME, sizeof(stringOfDevice), &stringOfDevice, NULL); printf("\033[0;31m(Platforms[%d], Devices[%d])\033[0;37m: %s\n", i, j, stringOfDevice); clPrintDevInfo(clDeviceIDs[j]); cl_device_type type; clGetDeviceInfo(clDeviceIDs[j], CL_DEVICE_TYPE, sizeof(type), &type, NULL); if( type & CL_DEVICE_TYPE_CPU ){ printf("\n----- Compute In %s -----\n", "CL_DEVICE_TYPE_CPU"); ret = pthread_create(&threads[i+j*numDevices], NULL, computeInDevice, clDeviceIDs[j]); pthread_join(threads[i+j*numDevices], NULL); } else if( type & CL_DEVICE_TYPE_GPU ){ printf("\n----- Compute In %s -----\n", "CL_DEVICE_TYPE_GPU"); ret = pthread_create(&threads[i+j*numDevices], NULL, computeInDevice, clDeviceIDs[j]); pthread_join(threads[i+j*numDevices], NULL); } else if( type & CL_DEVICE_TYPE_ACCELERATOR ){ printf("\n----- Compute In %s -----\n", "CL_DEVICE_TYPE_ACCELERATOR"); } else if( type & CL_DEVICE_TYPE_DEFAULT ){ printf("\n----- Compute In %s -----\n", "CL_DEVICE_TYPE_DEFAULT"); } } printf("\n"); } free(A); free(B); free(C); free(seqOutput); return 0; }
int main(int argc, const char** argv) { // start logs printf("clDeviceQuery Starting...\n\n"); bool bPassed = true; std::string sProfileString = "clDeviceQuery, Platform Name = "; // Get OpenCL platform ID for NVIDIA if avaiable, otherwise default char cBuffer[1024]; cl_platform_id clSelectedPlatformID = NULL; cl_platform_id* clPlatformIDs; cl_uint num_platforms; cl_int ciErrNum = clGetPlatformIDs(0, NULL, &num_platforms); if (ciErrNum != CL_SUCCESS) { printf(" Error %i in clGetPlatformIDs Call!\n\n", ciErrNum); bPassed = false; } else { if (num_platforms == 0) { printf("No OpenCL platform found!\n\n"); bPassed = false; } else { // if there's one platform or more, make space for ID's if ((clPlatformIDs = (cl_platform_id*)malloc(num_platforms * sizeof(cl_platform_id))) == NULL) { printf("Failed to allocate memory for cl_platform ID's!\n\n"); bPassed = false; } printf("%d OpenCL Platforms found\n\n", num_platforms); // get platform info for each platform ciErrNum = clGetPlatformIDs (num_platforms, clPlatformIDs, NULL); for(cl_uint i = 0; i < num_platforms; ++i) { ciErrNum = clGetPlatformInfo (clPlatformIDs[i], CL_PLATFORM_NAME, 1024, &cBuffer, NULL); if(ciErrNum == CL_SUCCESS) { clSelectedPlatformID = clPlatformIDs[i]; // Get OpenCL platform name and version ciErrNum = clGetPlatformInfo (clSelectedPlatformID, CL_PLATFORM_NAME, sizeof(cBuffer), cBuffer, NULL); if (ciErrNum == CL_SUCCESS) { printf(" CL_PLATFORM_NAME: \t%s\n", cBuffer); sProfileString += cBuffer; } else { printf(" Error %i in clGetPlatformInfo Call !!!\n\n", ciErrNum); bPassed = false; } sProfileString += ", Platform Version = "; ciErrNum = clGetPlatformInfo (clSelectedPlatformID, CL_PLATFORM_VERSION, sizeof(cBuffer), cBuffer, NULL); if (ciErrNum == CL_SUCCESS) { printf(" CL_PLATFORM_VERSION: \t%s\n", cBuffer); sProfileString += cBuffer; } else { printf(" Error %i in clGetPlatformInfo Call !!!\n\n", ciErrNum); bPassed = false; } // Log OpenCL SDK Version # (for convenience: not specific to OpenCL) sProfileString += ", NumDevs = "; // Get and log OpenCL device info cl_uint ciDeviceCount; cl_device_id *devices; printf("OpenCL Device Info:\n\n"); ciErrNum = clGetDeviceIDs (clSelectedPlatformID, CL_DEVICE_TYPE_ALL, 0, NULL, &ciDeviceCount); // check for 0 devices found or errors... if (ciDeviceCount == 0) { printf(" No devices found supporting OpenCL (return code %i)\n\n", ciErrNum); bPassed = false; sProfileString += "0"; } else if (ciErrNum != CL_SUCCESS) { printf(" Error %i in clGetDeviceIDs call !!!\n\n", ciErrNum); bPassed = false; } else { // Get and log the OpenCL device ID's ciErrNum = clGetPlatformInfo (clSelectedPlatformID, CL_PLATFORM_NAME, sizeof(cBuffer), cBuffer, NULL); printf(" %u devices found supporting OpenCL on: %s\n\n", ciDeviceCount, cBuffer); char cTemp[2]; sprintf(cTemp, "%u", ciDeviceCount); sProfileString += cTemp; if ((devices = (cl_device_id*)malloc(sizeof(cl_device_id) * ciDeviceCount)) == NULL) { printf(" Failed to allocate memory for devices !!!\n\n"); bPassed = false; } ciErrNum = clGetDeviceIDs (clSelectedPlatformID, CL_DEVICE_TYPE_ALL, ciDeviceCount, devices, &ciDeviceCount); if (ciErrNum == CL_SUCCESS) { for(unsigned int i = 0; i < ciDeviceCount; ++i ) { printf(" ----------------------------------\n"); clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(cBuffer), &cBuffer, NULL); printf(" Device %s\n", cBuffer); printf(" ---------------------------------\n"); clPrintDevInfo(devices[i]); sProfileString += ", Device = "; sProfileString += cBuffer; } } else { printf(" Error %i in clGetDeviceIDs call !!!\n\n", ciErrNum); bPassed = false; } } // masterlog info sProfileString += "\n"; printf("%s", sProfileString.c_str()); } free(clPlatformIDs); } } } // Log system info(for convenience: not specific to OpenCL) printf( "\nSystem Info: \n\n"); char timestr[255]; time_t now = time(NULL); struct tm *ts; ts = localtime(&now); strftime(timestr, 255, " %H:%M:%S, %m/%d/%Y",ts); // write time and date to logs printf(" Local Time/Date = %s\n", timestr); // write proc and OS info to logs // parse /proc/cpuinfo std::ifstream cpuinfo( "/proc/cpuinfo" ); // open the file in /proc std::string tmp; int cpu_num = 0; std::string cpu_name = "none"; do { cpuinfo >> tmp; if( tmp == "processor" ) cpu_num++; if( tmp == "name" ) { cpuinfo >> tmp; // skip : std::stringstream tmp_stream(""); do { cpuinfo >> tmp; if (tmp != std::string("stepping")) { tmp_stream << tmp.c_str() << " "; } } while (tmp != std::string("stepping")); cpu_name = tmp_stream.str(); } } while ( (! cpuinfo.eof()) ); // Linux version std::ifstream version( "/proc/version" ); char versionstr[255]; version.getline(versionstr, 255); printf(" CPU Name: %s\n # of CPU processors: %u\n %s\n\n\n", cpu_name.c_str(),cpu_num,versionstr); // finish printf("TEST %s\n\n", bPassed ? "PASSED" : "FAILED !!!"); }