void CreatePlatformDlg::accept() { const QString platformName = GetPlatformName(); if (!platformName.isNull() && !platformName.isEmpty()) { if (GetHeight() > 0 && GetWidth() > 0) { if(!HierarchyTreeController::Instance()->GetTree().IsPlatformNamePresent(platformName) ) { QDialog::accept(); } else { QMessageBox msgBox; msgBox.setText(tr("Please fill platform name field with unique value.")); msgBox.exec(); } } else { QMessageBox msgBox; msgBox.setText(tr("Platform height and weight should have non-zero value!")); msgBox.exec(); } } else { QMessageBox msgBox; msgBox.setText(tr("Please fill platform name field with value. It can't be empty.")); msgBox.exec(); } }
void CRegistry::Init(void) { LONG lResult; DWORD dwDisposition; char szModelKey[1024]; wsprintf(szModelKey, "Software\\Valve\\%s\\Settings\\", GetPlatformName()); lResult = RegCreateKeyEx(HKEY_CURRENT_USER, szModelKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &m_hKey, &dwDisposition); if (lResult != ERROR_SUCCESS) { m_bValid = false; return; } m_bValid = true; }
JNIEXPORT jstring JNICALL Java_org_opencv_engine_HardwareDetector_GetPlatformName(JNIEnv* env, jclass) { std::string hardware_name = GetPlatformName(); return env->NewStringUTF(hardware_name.c_str()); }
/* * Parse Commandline. */ IOR_test_t *ParseCommandLine(int argc, char **argv) { static const char *opts = "a:A:b:BcCd:D:eEf:FgG:hHi:Ij:J:kKlL:mM:nN:o:O:pPqQ:rRs:St:T:uU:vVwWxX:YzZ"; int c, i; static IOR_test_t *tests = NULL; /* suppress getopt() error message when a character is unrecognized */ opterr = 0; init_IOR_Param_t(&initialTestParams); GetPlatformName(initialTestParams.platform); initialTestParams.writeFile = initialTestParams.readFile = FALSE; initialTestParams.checkWrite = initialTestParams.checkRead = FALSE; while ((c = getopt(argc, argv, opts)) != -1) { switch (c) { case 'A': initialTestParams.referenceNumber = atoi(optarg); break; case 'a': strcpy(initialTestParams.api, optarg); break; case 'b': initialTestParams.blockSize = StringToBytes(optarg); RecalculateExpectedFileSize(&initialTestParams); break; case 'B': initialTestParams.useO_DIRECT = TRUE; break; case 'c': initialTestParams.collective = TRUE; break; case 'C': initialTestParams.reorderTasks = TRUE; break; case 'Q': initialTestParams.taskPerNodeOffset = atoi(optarg); break; case 'Z': initialTestParams.reorderTasksRandom = TRUE; break; case 'X': initialTestParams.reorderTasksRandomSeed = atoi(optarg); break; case 'd': initialTestParams.interTestDelay = atoi(optarg); break; case 'D': initialTestParams.deadlineForStonewalling = atoi(optarg); break; case 'Y': initialTestParams.fsyncPerWrite = TRUE; break; case 'e': initialTestParams.fsync = TRUE; break; case 'E': initialTestParams.useExistingTestFile = TRUE; break; case 'f': tests = ReadConfigScript(optarg); break; case 'F': initialTestParams.filePerProc = TRUE; break; case 'g': initialTestParams.intraTestBarriers = TRUE; break; case 'G': initialTestParams.setTimeStampSignature = atoi(optarg); break; case 'h': initialTestParams.showHelp = TRUE; break; case 'H': initialTestParams.showHints = TRUE; break; case 'i': initialTestParams.repetitions = atoi(optarg); break; case 'I': initialTestParams.individualDataSets = TRUE; break; case 'j': initialTestParams.outlierThreshold = atoi(optarg); break; case 'J': initialTestParams.setAlignment = StringToBytes(optarg); break; case 'k': initialTestParams.keepFile = TRUE; break; case 'K': initialTestParams.keepFileWithError = TRUE; break; case 'l': initialTestParams.storeFileOffset = TRUE; break; case 'L': initialTestParams.interOpDelay = atoi(optarg); break; case 'M': initialTestParams.memoryPerNode = NodeMemoryStringToBytes(optarg); break; case 'm': initialTestParams.multiFile = TRUE; break; case 'n': initialTestParams.noFill = TRUE; break; case 'N': initialTestParams.numTasks = atoi(optarg); RecalculateExpectedFileSize(&initialTestParams); break; case 'o': strcpy(initialTestParams.testFileName, optarg); break; case 'O': ParseLine(optarg, &initialTestParams); break; case 'p': initialTestParams.preallocate = TRUE; break; case 'P': initialTestParams.useSharedFilePointer = TRUE; break; case 'q': initialTestParams.quitOnError = TRUE; break; case 'r': initialTestParams.readFile = TRUE; break; case 'R': initialTestParams.checkRead = TRUE; break; case 's': initialTestParams.segmentCount = atoi(optarg); RecalculateExpectedFileSize(&initialTestParams); break; case 'S': initialTestParams.useStridedDatatype = TRUE; break; case 't': initialTestParams.transferSize = StringToBytes(optarg); break; case 'T': initialTestParams.maxTimeDuration = atoi(optarg); break; case 'u': initialTestParams.uniqueDir = TRUE; break; case 'U': strcpy(initialTestParams.hintsFileName, optarg); break; case 'v': initialTestParams.verbose++; break; case 'V': initialTestParams.useFileView = TRUE; break; case 'w': initialTestParams.writeFile = TRUE; break; case 'W': initialTestParams.checkWrite = TRUE; break; case 'x': initialTestParams.singleXferAttempt = TRUE; break; case 'z': initialTestParams.randomOffset = TRUE; break; default: fprintf(stdout, "ParseCommandLine: unknown option `-%c'.\n", optopt); } } for (i = optind; i < argc; i++) fprintf(stdout, "non-option argument: %s\n", argv[i]); /* If an IOR script was not used, initialize test queue to the defaults */ if (tests == NULL) { tests = CreateTest(&initialTestParams, 0); AllocResults(tests); } CheckRunSettings(tests); return (tests); }
PLUGIN_EXPORT LPCWSTR GetString(void* data) { MeasureData* measure = (MeasureData*)data; static WCHAR sBuffer[256]; DWORD sBufferLen = _countof(sBuffer); BYTE tmpBuffer[7168]; ULONG tmpBufferLen = _countof(tmpBuffer); auto convertToWide = [&](LPCSTR str)->LPCWSTR { MultiByteToWideChar(CP_ACP, 0, str, -1, sBuffer, 256); return sBuffer; }; switch (measure->type) { case MEASURE_COMPUTER_NAME: GetComputerName(sBuffer, &sBufferLen); return sBuffer; case MEASURE_USER_NAME: GetUserName(sBuffer, &sBufferLen); return sBuffer; case MEASURE_WORK_AREA: wsprintf(sBuffer, L"%i x %i", GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)); return sBuffer; case MEASURE_SCREEN_SIZE: wsprintf(sBuffer, L"%i x %i", GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); return sBuffer; case MEASURE_OS_VERSION: return GetPlatformName(); case MEASURE_ADAPTER_DESCRIPTION: if (ERROR_SUCCESS == GetAdaptersInfo((IP_ADAPTER_INFO*)tmpBuffer, &tmpBufferLen)) { PIP_ADAPTER_INFO info = (IP_ADAPTER_INFO*)tmpBuffer; int i = 0; while (info) { if (i == measure->data) { return convertToWide(info->Description); } info = info->Next; i++; } } break; case MEASURE_IP_ADDRESS: if (NO_ERROR == GetIpAddrTable((PMIB_IPADDRTABLE)tmpBuffer, &tmpBufferLen, FALSE)) { PMIB_IPADDRTABLE ipTable = (PMIB_IPADDRTABLE)tmpBuffer; if (measure->data >= 1000) { measure->data = measure->data - 999; for (UINT i = 0; i < ipTable->dwNumEntries; ++i) { if ((ipTable->table[i].wType) & MIB_IPADDR_DISCONNECTED) continue; --measure->data; if (measure->data == 0) { DWORD ip = ipTable->table[i].dwAddr; wsprintf(sBuffer, L"%i.%i.%i.%i", ip % 256, (ip >> 8) % 256, (ip >> 16) % 256, (ip >> 24) % 256); return sBuffer; } } }
int main(int argc, char **argv) { ////Part 1 - handle command line options such as device selection, verbosity, etc. int platform_id = 0; int device_id = 0; for (int i = 1; i < argc; i++) { if ((strcmp(argv[i], "-p") == 0) && (i < (argc - 1))) { platform_id = atoi(argv[++i]); } else if ((strcmp(argv[i], "-d") == 0) && (i < (argc - 1))) { device_id = atoi(argv[++i]); } else if (strcmp(argv[i], "-l") == 0) { std::cout << ListPlatformsDevices() << std::endl; } else if (strcmp(argv[i], "-h") == 0) { print_help(); } } ifstream inFile; //create obkject of class inFile.open("temp_lincolnshire.txt"); //open file //check for error if (inFile.fail()) { cerr << "Error opening File" <<endl; exit(1); } else { cout << "Reading file, this may take some time" << endl; } int count = 0; string location; int year; int month; int day; int time; float temp; std::vector<string> locations; std::vector<int> years; std::vector<int> months; std::vector<int> days; std::vector<int> times; std::vector<int> temps; //read file until end is reached while (!inFile.eof()) { inFile >> location >> year >> month >> day >> time >> temp; locations.push_back(location); years.push_back(year); months.push_back(month); days.push_back(day); times.push_back(time); temps.push_back((int)temp); count++; } cout << "File read complete, " << count << " items found" << endl; //detect any potential exceptions try { //Part 2 - host operations //2.1 Select computing devices cl::Context context = GetContext(platform_id, device_id); //display the selected device std::cout << "Runinng on " << GetPlatformName(platform_id) << ", " << GetDeviceName(platform_id, device_id) << std::endl; //create a queue to which we will push commands for the device cl::CommandQueue queue(context); //2.2 Load & build the device code cl::Program::Sources sources; AddSources(sources, "my_kernels3.cl"); cl::Program program(context, sources); //build and debug the kernel code try { program.build(); } catch (const cl::Error& err) { std::cout << "Build Status: " << program.getBuildInfo<CL_PROGRAM_BUILD_STATUS>(context.getInfo<CL_CONTEXT_DEVICES>()[0]) << std::endl; std::cout << "Build Options:\t" << program.getBuildInfo<CL_PROGRAM_BUILD_OPTIONS>(context.getInfo<CL_CONTEXT_DEVICES>()[0]) << std::endl; std::cout << "Build Log:\t " << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(context.getInfo<CL_CONTEXT_DEVICES>()[0]) << std::endl; throw err; } typedef int mytype; //input std::vector<int> A = temps; //AVG / SUM std::vector<int> minTemps = temps; //MIN std::vector<int> maxTemps = temps; //MAX //number of input elements size_t original_Length = A.size(); //the following part adjusts the length of the input vector so it can be run for a specific workgroup size //if the total input length is divisible by the workgroup size //this makes the code more efficient size_t local_size = 1024; size_t padding_size = A.size() % local_size; //if the input vector is not a multiple of the local_size //insert additional neutral elements so that the total will not be affected if (padding_size) { //AVERAGE std::vector<int> A_ext(local_size-padding_size, 0); //MINIMUM std::vector<int> minTemps_ext(local_size - padding_size, INT_MAX); //MAXIMUM std::vector<int> maxTemps_ext(local_size - padding_size, INT_MIN); //append that extra vector to our input A.insert(A.end(), A_ext.begin(), A_ext.end()); minTemps.insert(minTemps.end(), minTemps_ext.begin(), minTemps_ext.end()); maxTemps.insert(maxTemps.end(), maxTemps_ext.begin(), maxTemps_ext.end()); } size_t input_elements = A.size(); //number of input elements with padding size_t input_size = A.size()*sizeof(mytype); //size in bytes size_t nr_groups = input_elements / local_size; //host - output //max - min + 1 for hist size std::vector<mytype> output(1); size_t output_size = output.size()*sizeof(mytype);//size in bytes //device - buffers cl::Buffer buffer_A(context, CL_MEM_READ_ONLY, input_size); cl::Buffer buffer_minTemps(context, CL_MEM_READ_ONLY, input_size); cl::Buffer buffer_maxTemps(context, CL_MEM_READ_ONLY, input_size); cl::Buffer buffer_output(context, CL_MEM_READ_WRITE, output_size); //----------------------------------------------------------------------------------------------------------------- //5.1 copy array A to and initialise other arrays on device memory queue.enqueueWriteBuffer(buffer_minTemps, CL_TRUE, 0, input_size, &minTemps[0]); queue.enqueueFillBuffer(buffer_output, INT_MAX, 0, output_size); //5.2 Setup and execute all kernels (i.e. device code) cl::Kernel kernel_1 = cl::Kernel(program, "minVal"); kernel_1.setArg(0, buffer_minTemps); kernel_1.setArg(1, buffer_output); kernel_1.setArg(2, cl::Local(local_size*sizeof(mytype)));//local memory size //call all kernels in a sequence queue.enqueueNDRangeKernel(kernel_1, cl::NullRange, cl::NDRange(input_elements), cl::NDRange(local_size)); //5.3 Copy the result from device to host queue.enqueueReadBuffer(buffer_output, CL_TRUE, 0, output_size, &output[0]); int minimumTemp = output[0]; //------------------------------------------------------------------------------------------------------------------ //5.1 copy array A to and initialise other arrays on device memory queue.enqueueWriteBuffer(buffer_maxTemps, CL_TRUE, 0, input_size, &maxTemps[0]); queue.enqueueFillBuffer(buffer_output, INT_MIN, 0, output_size); //5.2 Setup and execute all kernels (i.e. device code) cl::Kernel kernel_2 = cl::Kernel(program, "maxVal"); kernel_2.setArg(0, buffer_maxTemps); kernel_2.setArg(1, buffer_output); kernel_2.setArg(2, cl::Local(local_size*sizeof(mytype)));//local memory size //call all kernels in a sequence queue.enqueueNDRangeKernel(kernel_2, cl::NullRange, cl::NDRange(input_elements), cl::NDRange(local_size)); //5.3 Copy the result from device to host queue.enqueueReadBuffer(buffer_output, CL_TRUE, 0, output_size, &output[0]); int maximumTemp = output[0]; //------------------------------------------------------------------------------------------------------------------- //5.1 copy array A to and initialise other arrays on device memory queue.enqueueWriteBuffer(buffer_A, CL_TRUE, 0, input_size, &A[0]); queue.enqueueFillBuffer(buffer_output, 0, 0, output_size); //5.2 Setup and execute all kernels (i.e. device code) cl::Kernel kernel_3 = cl::Kernel(program, "sum"); kernel_3.setArg(0, buffer_A); kernel_3.setArg(1, buffer_output); kernel_3.setArg(2, cl::Local(local_size*sizeof(mytype)));//local memory size //call all kernels in a sequence queue.enqueueNDRangeKernel(kernel_3, cl::NullRange, cl::NDRange(input_elements), cl::NDRange(local_size)); //5.3 Copy the result from device to host queue.enqueueReadBuffer(buffer_output, CL_TRUE, 0, output_size, &output[0]); double avgTemp = 1.00* output[0] / original_Length; //----------------------------------------------------------------------------------------------------------------- int binCount = 20; int range = (maximumTemp - minimumTemp) + 1; int minVal = minimumTemp; cout << "How many bins would you like in your histogram" << endl; cin >> binCount; std::vector<mytype> histOutput(binCount); size_t hist_output_size = histOutput.size()*sizeof(mytype);//size in bytes std::vector<mytype> his_bin = { binCount }; size_t hist_binCount_size = his_bin.size()*sizeof(mytype);//size in bytes std::vector<mytype> his_range = { range }; size_t hist_range_size = his_range.size()*sizeof(mytype);//size in bytes std::vector<mytype> his_min = { minimumTemp }; size_t hist_min_size = his_min.size()*sizeof(mytype);//size in bytes //device - buffer cl::Buffer buffer_histOutput(context, CL_MEM_READ_WRITE, hist_output_size); cl::Buffer buffer_bin(context, CL_MEM_READ_WRITE, hist_binCount_size); cl::Buffer buffer_range(context, CL_MEM_READ_WRITE, hist_range_size); cl::Buffer buffer_minimum(context, CL_MEM_READ_WRITE, hist_min_size); //5.1 copy array A to and initialise other arrays on device memory queue.enqueueWriteBuffer(buffer_minTemps, CL_TRUE, 0, input_size, &minTemps[0]); queue.enqueueFillBuffer(buffer_histOutput, 0, 0, hist_output_size); queue.enqueueWriteBuffer(buffer_bin, CL_TRUE, 0, hist_binCount_size, &his_bin[0]); queue.enqueueWriteBuffer(buffer_range, CL_TRUE, 0, hist_range_size, &his_range[0]); queue.enqueueWriteBuffer(buffer_minimum, CL_TRUE, 0, hist_min_size, &his_min[0]); //5.2 Setup and execute all kernels (i.e. device code) cl::Kernel kernel_4 = cl::Kernel(program, "hist2"); kernel_4.setArg(0, buffer_minTemps); kernel_4.setArg(1, buffer_histOutput); kernel_4.setArg(2, buffer_bin); kernel_4.setArg(3, buffer_range); kernel_4.setArg(4, buffer_minimum); //call all kernels in a sequence queue.enqueueNDRangeKernel(kernel_4, cl::NullRange, cl::NDRange(input_elements), cl::NDRange(local_size)); //5.3 Copy the result from device to host queue.enqueueReadBuffer(buffer_histOutput, CL_TRUE, 0, hist_output_size, &histOutput[0]); //-------------------------------------------------------------------------------------------------------------------- std::cout << "\nMinimum Temp = " << minimumTemp << std::endl; std::cout << "Maximum Temp = " << maximumTemp << std::endl; std::cout << "Average Temp = " << avgTemp << std::endl; std::cout << "\nHistogram:\n " << std::endl; std::cout << histOutput << std::endl; cin.get(); } catch (cl::Error err) { std::cerr << "ERROR: " << err.what() << ", " << getErrorString(err.err()) << std::endl; } cin.get(); return 0; }