From e0cf44224239f4546cdc2d0dec9ae3aa684af390 Mon Sep 17 00:00:00 2001 From: Krishnaraj Bhat Date: Sun, 20 Oct 2019 13:46:22 +0530 Subject: [PATCH] [src] auto format cpp files --- .gitignore | 1 + src/clpeak.cpp | 82 ++++++++++++++++++++------------------ src/common.cpp | 28 ++++++------- src/compute_dp.cpp | 26 +++++++----- src/compute_hp.cpp | 26 +++++++----- src/compute_integer.cpp | 24 ++++++----- src/compute_sp.cpp | 24 ++++++----- src/entry.cpp | 2 +- src/entry_android.cpp | 20 +++++----- src/global_bandwidth.cpp | 44 ++++++++++++-------- src/kernel_latency.cpp | 13 +++--- src/logger.cpp | 25 +++++------- src/logger_android.cpp | 33 +++++++++------ src/options.cpp | 66 +++++++++++++++--------------- src/transfer_bandwidth.cpp | 74 ++++++++++++++++++++-------------- 15 files changed, 267 insertions(+), 221 deletions(-) diff --git a/.gitignore b/.gitignore index 567609b..01f9cb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +.vscode/ \ No newline at end of file diff --git a/src/clpeak.cpp b/src/clpeak.cpp index 7120864..8708463 100644 --- a/src/clpeak.cpp +++ b/src/clpeak.cpp @@ -4,31 +4,34 @@ #define MSTRINGIFY(...) #__VA_ARGS__ static const char *stringifiedKernels = - #include "global_bandwidth_kernels.cl" - #include "compute_sp_kernels.cl" - #include "compute_hp_kernels.cl" - #include "compute_dp_kernels.cl" - #include "compute_integer_kernels.cl" +#include "global_bandwidth_kernels.cl" +#include "compute_sp_kernels.cl" +#include "compute_hp_kernels.cl" +#include "compute_dp_kernels.cl" +#include "compute_integer_kernels.cl" ; #ifdef USE_STUB_OPENCL // Prototype -extern "C" { -void stubOpenclReset(); +extern "C" +{ + void stubOpenclReset(); } #endif - -clPeak::clPeak(): forcePlatform(false), forceDevice(false), useEventTimer(false), - isGlobalBW(true), isComputeSP(true), isComputeDP(true), isComputeInt(true), - isTransferBW(true), isKernelLatency(true), - specifiedPlatform(0), specifiedDevice(0) +clPeak::clPeak() : forcePlatform(false), forceDevice(false), useEventTimer(false), + isGlobalBW(true), isComputeSP(true), isComputeDP(true), isComputeInt(true), + isTransferBW(true), isKernelLatency(true), + specifiedPlatform(0), specifiedDevice(0) { } clPeak::~clPeak() { - if(log) delete log; + if (log) + { + delete log; + } } int clPeak::runAll() @@ -43,9 +46,9 @@ int clPeak::runAll() log->xmlOpenTag("clpeak"); log->xmlAppendAttribs("os", OS_NAME); - for(size_t p=0; p < platforms.size(); p++) + for (size_t p = 0; p < platforms.size(); p++) { - if(forcePlatform && (p != specifiedPlatform)) + if (forcePlatform && (p != specifiedPlatform)) continue; std::string platformName = platforms[p].getInfo(); @@ -56,30 +59,32 @@ int clPeak::runAll() log->xmlAppendAttribs("name", platformName); cl_context_properties cps[3] = { - CL_CONTEXT_PLATFORM, - (cl_context_properties)(platforms[p])(), - 0 - }; + CL_CONTEXT_PLATFORM, + (cl_context_properties)(platforms[p])(), + 0}; cl::Context ctx(CL_DEVICE_TYPE_ALL, cps); vector devices = ctx.getInfo(); - cl::Program::Sources source(1, make_pair(stringifiedKernels, (strlen(stringifiedKernels)+1))); + cl::Program::Sources source(1, make_pair(stringifiedKernels, (strlen(stringifiedKernels) + 1))); cl::Program prog = cl::Program(ctx, source); - for(size_t d=0; d < devices.size(); d++) + for (size_t d = 0; d < devices.size(); d++) { - if(forceDevice && (d != specifiedDevice)) + if (forceDevice && (d != specifiedDevice)) continue; device_info_t devInfo = getDeviceInfo(devices[d]); log->print(TAB "Device: " + devInfo.deviceName + NEWLINE); log->print(TAB TAB "Driver version : "); - log->print(devInfo.driverVersion); log->print(" (" OS_NAME ")" NEWLINE); + log->print(devInfo.driverVersion); + log->print(" (" OS_NAME ")" NEWLINE); log->print(TAB TAB "Compute units : "); - log->print(devInfo.numCUs); log->print(NEWLINE); + log->print(devInfo.numCUs); + log->print(NEWLINE); log->print(TAB TAB "Clock frequency : "); - log->print(devInfo.maxClockFreq); log->print(" MHz" NEWLINE); + log->print(devInfo.maxClockFreq); + log->print(" MHz" NEWLINE); log->xmlOpenTag("device"); log->xmlAppendAttribs("name", devInfo.deviceName); log->xmlAppendAttribs("driver_version", devInfo.driverVersion); @@ -95,8 +100,7 @@ int clPeak::runAll() catch (cl::Error &error) { UNUSED(error); - log->print(TAB TAB "Build Log: " + prog.getBuildInfo(devices[d]) - + NEWLINE NEWLINE); + log->print(TAB TAB "Build Log: " + prog.getBuildInfo(devices[d]) + NEWLINE NEWLINE); continue; } @@ -111,13 +115,13 @@ int clPeak::runAll() runKernelLatency(queue, prog, devInfo); log->print(NEWLINE); - log->xmlCloseTag(); // device + log->xmlCloseTag(); // device } - log->xmlCloseTag(); // platform + log->xmlCloseTag(); // platform } - log->xmlCloseTag(); // clpeak + log->xmlCloseTag(); // clpeak } - catch(cl::Error &error) + catch (cl::Error &error) { stringstream ss; ss << error.what() << " (" << error.err() << ")" NEWLINE; @@ -125,20 +129,19 @@ int clPeak::runAll() log->print(ss.str()); // skip error for no platform - if(strcmp(error.what(), "clGetPlatformIDs") == 0) + if (strcmp(error.what(), "clGetPlatformIDs") == 0) { - log->print("no platforms found" NEWLINE); + log->print("no platforms found" NEWLINE); } else { - return -1; + return -1; } } return 0; } - float clPeak::run_kernel(cl::CommandQueue &queue, cl::Kernel &kernel, cl::NDRange &globalSize, cl::NDRange &localSize, uint iters) { float timed = 0; @@ -148,9 +151,9 @@ float clPeak::run_kernel(cl::CommandQueue &queue, cl::Kernel &kernel, cl::NDRang queue.enqueueNDRangeKernel(kernel, cl::NullRange, globalSize, localSize); queue.finish(); - if(useEventTimer) + if (useEventTimer) { - for(uint i=0; i(); - if( (vendor.find("QUALCOMM") != std::string::npos) || - (vendor.find("qualcomm") != std::string::npos) ) + if ((vendor.find("QUALCOMM") != std::string::npos) || + (vendor.find("qualcomm") != std::string::npos)) { devInfo.maxWGSize = MIN(devInfo.maxWGSize, 128); } @@ -40,22 +40,25 @@ device_info_t getDeviceInfo(cl::Device &d) std::string extns = d.getInfo(); - if((extns.find("cl_khr_fp16") != std::string::npos)) + if ((extns.find("cl_khr_fp16") != std::string::npos)) devInfo.halfSupported = true; - if((extns.find("cl_khr_fp64") != std::string::npos) || (extns.find("cl_amd_fp64") != std::string::npos)) + if ((extns.find("cl_khr_fp64") != std::string::npos) || (extns.find("cl_amd_fp64") != std::string::npos)) devInfo.doubleSupported = true; devInfo.deviceType = d.getInfo(); - if(devInfo.deviceType & CL_DEVICE_TYPE_CPU) { + if (devInfo.deviceType & CL_DEVICE_TYPE_CPU) + { devInfo.gloalBWIters = 20; devInfo.globalBWMaxSize = 1 << 27; devInfo.computeWgsPerCU = 512; devInfo.computeDPWgsPerCU = 256; devInfo.computeIters = 10; devInfo.transferBWMaxSize = 1 << 27; - } else { // GPU + } + else + { // GPU devInfo.gloalBWIters = 50; devInfo.globalBWMaxSize = 1 << 29; devInfo.computeWgsPerCU = 2048; @@ -69,7 +72,6 @@ device_info_t getDeviceInfo(cl::Device &d) return devInfo; } - float timeInUS(cl::Event &timeEvent) { cl_ulong start = timeEvent.getProfilingInfo() / 1000; @@ -78,25 +80,22 @@ float timeInUS(cl::Event &timeEvent) return (float)((int)end - (int)start); } - void Timer::start() { tick = chrono::high_resolution_clock::now(); } - float Timer::stopAndTime() { tock = chrono::high_resolution_clock::now(); return (float)(chrono::duration_cast(tock - tick).count()); } - void populate(float *ptr, uint64_t N) { srand((unsigned int)time(NULL)); - for(uint64_t i=0; i maxValue)? maxValue: number; + uint64_t n = (number > maxValue) ? maxValue : number; return (n / base) * base; } @@ -125,7 +123,7 @@ void trimString(std::string &str) { size_t pos = str.find('\0'); - if(pos != std::string::npos) + if (pos != std::string::npos) { str.erase(pos); } diff --git a/src/compute_dp.cpp b/src/compute_dp.cpp index d1359af..6661c16 100644 --- a/src/compute_dp.cpp +++ b/src/compute_dp.cpp @@ -1,6 +1,5 @@ #include - int clPeak::runComputeDP(cl::CommandQueue &queue, cl::Program &prog, device_info_t &devInfo) { float timed, gflops; @@ -9,10 +8,10 @@ int clPeak::runComputeDP(cl::CommandQueue &queue, cl::Program &prog, device_info cl_double A = 1.3f; uint iters = devInfo.computeIters; - if(!isComputeDP) + if (!isComputeDP) return 0; - if(!devInfo.doubleSupported) + if (!devInfo.doubleSupported) { log->print(NEWLINE TAB TAB "No double precision support! Skipped" NEWLINE); return 0; @@ -54,13 +53,14 @@ int clPeak::runComputeDP(cl::CommandQueue &queue, cl::Program &prog, device_info // Vector width 1 log->print(TAB TAB TAB "double : "); - workPerWI = 4096; // Indicates flops executed per work-item + workPerWI = 4096; // Indicates flops executed per work-item timed = run_kernel(queue, kernel_v1, globalSize, localSize, iters); gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("double", gflops); /////////////////////////////////////////////////////////////////////////// @@ -73,7 +73,8 @@ int clPeak::runComputeDP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("double2", gflops); /////////////////////////////////////////////////////////////////////////// @@ -86,7 +87,8 @@ int clPeak::runComputeDP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("double4", gflops); /////////////////////////////////////////////////////////////////////////// @@ -98,7 +100,8 @@ int clPeak::runComputeDP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("double8", gflops); /////////////////////////////////////////////////////////////////////////// @@ -111,12 +114,13 @@ int clPeak::runComputeDP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("double16", gflops); /////////////////////////////////////////////////////////////////////////// - log->xmlCloseTag(); // double_precision_compute + log->xmlCloseTag(); // double_precision_compute } - catch(cl::Error &error) + catch (cl::Error &error) { stringstream ss; ss << error.what() << " (" << error.err() << ")" NEWLINE diff --git a/src/compute_hp.cpp b/src/compute_hp.cpp index 25835b6..09c8cc5 100644 --- a/src/compute_hp.cpp +++ b/src/compute_hp.cpp @@ -1,6 +1,5 @@ #include - int clPeak::runComputeHP(cl::CommandQueue &queue, cl::Program &prog, device_info_t &devInfo) { float timed, gflops; @@ -9,10 +8,10 @@ int clPeak::runComputeHP(cl::CommandQueue &queue, cl::Program &prog, device_info cl_float A = 1.3f; uint iters = devInfo.computeIters; - if(!isComputeDP) + if (!isComputeDP) return 0; - if(!devInfo.halfSupported) + if (!devInfo.halfSupported) { log->print(NEWLINE TAB TAB "No half precision support! Skipped" NEWLINE); return 0; @@ -54,13 +53,14 @@ int clPeak::runComputeHP(cl::CommandQueue &queue, cl::Program &prog, device_info // Vector width 1 log->print(TAB TAB TAB "half : "); - workPerWI = 4096; // Indicates flops executed per work-item + workPerWI = 4096; // Indicates flops executed per work-item timed = run_kernel(queue, kernel_v1, globalSize, localSize, iters); gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("half", gflops); /////////////////////////////////////////////////////////////////////////// @@ -73,7 +73,8 @@ int clPeak::runComputeHP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("half2", gflops); /////////////////////////////////////////////////////////////////////////// @@ -86,7 +87,8 @@ int clPeak::runComputeHP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("half4", gflops); /////////////////////////////////////////////////////////////////////////// @@ -98,7 +100,8 @@ int clPeak::runComputeHP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("half8", gflops); /////////////////////////////////////////////////////////////////////////// @@ -111,12 +114,13 @@ int clPeak::runComputeHP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("half16", gflops); /////////////////////////////////////////////////////////////////////////// - log->xmlCloseTag(); // half_precision_compute + log->xmlCloseTag(); // half_precision_compute } - catch(cl::Error &error) + catch (cl::Error &error) { stringstream ss; ss << error.what() << " (" << error.err() << ")" NEWLINE diff --git a/src/compute_integer.cpp b/src/compute_integer.cpp index 84057ad..2a4fff3 100644 --- a/src/compute_integer.cpp +++ b/src/compute_integer.cpp @@ -1,6 +1,5 @@ #include - int clPeak::runComputeInteger(cl::CommandQueue &queue, cl::Program &prog, device_info_t &devInfo) { float timed, gflops; @@ -9,7 +8,7 @@ int clPeak::runComputeInteger(cl::CommandQueue &queue, cl::Program &prog, device cl_int A = 4; uint iters = devInfo.computeIters; - if(!isComputeInt) + if (!isComputeInt) return 0; try @@ -48,13 +47,14 @@ int clPeak::runComputeInteger(cl::CommandQueue &queue, cl::Program &prog, device // Vector width 1 log->print(TAB TAB TAB "int : "); - workPerWI = 2048; // Indicates integer operations executed per work-item + workPerWI = 2048; // Indicates integer operations executed per work-item timed = run_kernel(queue, kernel_v1, globalSize, localSize, iters); gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("int", gflops); /////////////////////////////////////////////////////////////////////////// @@ -67,7 +67,8 @@ int clPeak::runComputeInteger(cl::CommandQueue &queue, cl::Program &prog, device gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("int2", gflops); /////////////////////////////////////////////////////////////////////////// @@ -80,7 +81,8 @@ int clPeak::runComputeInteger(cl::CommandQueue &queue, cl::Program &prog, device gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("int4", gflops); /////////////////////////////////////////////////////////////////////////// @@ -93,7 +95,8 @@ int clPeak::runComputeInteger(cl::CommandQueue &queue, cl::Program &prog, device gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("int8", gflops); /////////////////////////////////////////////////////////////////////////// @@ -106,12 +109,13 @@ int clPeak::runComputeInteger(cl::CommandQueue &queue, cl::Program &prog, device gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("int16", gflops); /////////////////////////////////////////////////////////////////////////// - log->xmlCloseTag(); // integer_compute + log->xmlCloseTag(); // integer_compute } - catch(cl::Error &error) + catch (cl::Error &error) { stringstream ss; ss << error.what() << " (" << error.err() << ")" NEWLINE diff --git a/src/compute_sp.cpp b/src/compute_sp.cpp index ee29a21..6d718fc 100644 --- a/src/compute_sp.cpp +++ b/src/compute_sp.cpp @@ -1,6 +1,5 @@ #include - int clPeak::runComputeSP(cl::CommandQueue &queue, cl::Program &prog, device_info_t &devInfo) { float timed, gflops; @@ -9,7 +8,7 @@ int clPeak::runComputeSP(cl::CommandQueue &queue, cl::Program &prog, device_info cl_float A = 1.3f; uint iters = devInfo.computeIters; - if(!isComputeSP) + if (!isComputeSP) return 0; try @@ -48,13 +47,14 @@ int clPeak::runComputeSP(cl::CommandQueue &queue, cl::Program &prog, device_info // Vector width 1 log->print(TAB TAB TAB "float : "); - workPerWI = 4096; // Indicates flops executed per work-item + workPerWI = 4096; // Indicates flops executed per work-item timed = run_kernel(queue, kernel_v1, globalSize, localSize, iters); gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("float", gflops); /////////////////////////////////////////////////////////////////////////// @@ -67,7 +67,8 @@ int clPeak::runComputeSP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("float2", gflops); /////////////////////////////////////////////////////////////////////////// @@ -80,7 +81,8 @@ int clPeak::runComputeSP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("float4", gflops); /////////////////////////////////////////////////////////////////////////// @@ -93,7 +95,8 @@ int clPeak::runComputeSP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("float8", gflops); /////////////////////////////////////////////////////////////////////////// @@ -106,12 +109,13 @@ int clPeak::runComputeSP(cl::CommandQueue &queue, cl::Program &prog, device_info gflops = (static_cast(globalWIs) * static_cast(workPerWI)) / timed / 1e3f; - log->print(gflops); log->print(NEWLINE); + log->print(gflops); + log->print(NEWLINE); log->xmlRecord("float16", gflops); /////////////////////////////////////////////////////////////////////////// - log->xmlCloseTag(); // single_precision_compute + log->xmlCloseTag(); // single_precision_compute } - catch(cl::Error &error) + catch (cl::Error &error) { stringstream ss; ss << error.what() << " (" << error.err() << ")" NEWLINE diff --git a/src/entry.cpp b/src/entry.cpp index 9735358..d5d5c3f 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -1,6 +1,6 @@ #include -int main(int argc, char ** argv) +int main(int argc, char **argv) { clPeak clObj; diff --git a/src/entry_android.cpp b/src/entry_android.cpp index cdcf15e..7a6cd11 100644 --- a/src/entry_android.cpp +++ b/src/entry_android.cpp @@ -1,7 +1,7 @@ #include #include -#define PRINT_CALLBACK "print_callback_from_c" +#define PRINT_CALLBACK "print_callback_from_c" jint JNICALL Java_kr_clpeak_jni_1connect_launchClpeak(JNIEnv *_jniEnv, jobject _jObject, jint argc, jobjectArray _argv) @@ -9,17 +9,20 @@ jint JNICALL Java_kr_clpeak_jni_1connect_launchClpeak(JNIEnv *_jniEnv, char **argv; clPeak clObj; - argv = (char **)malloc(sizeof(char*) * argc); + argv = (char **)malloc(sizeof(char *) * argc); // Convert jobjectArray to string array - for(int i=0; iGetObjectArrayElement(_argv, i); - argv[i] = (char*) _jniEnv->GetStringUTFChars(strObj, 0); + jstring strObj = (jstring)_jniEnv->GetObjectArrayElement(_argv, i); + argv[i] = (char *)_jniEnv->GetStringUTFChars(strObj, 0); } clObj.parseArgs(argc, argv); - if(argv) free(argv); + if (argv) + { + free(argv); + } clObj.log->jEnv = _jniEnv; clObj.log->jObj = &(_jObject); @@ -29,10 +32,9 @@ jint JNICALL Java_kr_clpeak_jni_1connect_launchClpeak(JNIEnv *_jniEnv, return clObj.runAll(); } - void Java_kr_clpeak_MainActivity_setenv(JNIEnv *jniEnv, jobject _jObj, jstring key, jstring value) { - setenv((char*) jniEnv->GetStringUTFChars(key, 0), - (char*) jniEnv->GetStringUTFChars(value, 0), 1); + setenv((char *)jniEnv->GetStringUTFChars(key, 0), + (char *)jniEnv->GetStringUTFChars(value, 0), 1); } diff --git a/src/global_bandwidth.cpp b/src/global_bandwidth.cpp index 04eb768..df07497 100644 --- a/src/global_bandwidth.cpp +++ b/src/global_bandwidth.cpp @@ -1,7 +1,6 @@ #include -#define FETCH_PER_WI 16 - +#define FETCH_PER_WI 16 int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, device_info_t &devInfo) { @@ -9,7 +8,7 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d cl::NDRange globalSize, localSize; float *arr = NULL; - if(!isGlobalBW) + if (!isGlobalBW) return 0; cl::Context ctx = queue.getInfo(); @@ -74,11 +73,12 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d // go -- global_size offset timed_lo = run_kernel(queue, kernel_v1_lo, globalSize, localSize, iters); timed_go = run_kernel(queue, kernel_v1_go, globalSize, localSize, iters); - timed = (timed_lo < timed_go)? timed_lo: timed_go; + timed = (timed_lo < timed_go) ? timed_lo : timed_go; gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("float", gbps); /////////////////////////////////////////////////////////////////////////// @@ -89,11 +89,12 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d timed_lo = run_kernel(queue, kernel_v2_lo, globalSize, localSize, iters); timed_go = run_kernel(queue, kernel_v2_go, globalSize, localSize, iters); - timed = (timed_lo < timed_go)? timed_lo: timed_go; + timed = (timed_lo < timed_go) ? timed_lo : timed_go; gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("float2", gbps); /////////////////////////////////////////////////////////////////////////// @@ -104,11 +105,12 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d timed_lo = run_kernel(queue, kernel_v4_lo, globalSize, localSize, iters); timed_go = run_kernel(queue, kernel_v4_go, globalSize, localSize, iters); - timed = (timed_lo < timed_go)? timed_lo: timed_go; + timed = (timed_lo < timed_go) ? timed_lo : timed_go; gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("float4", gbps); /////////////////////////////////////////////////////////////////////////// @@ -119,11 +121,12 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d timed_lo = run_kernel(queue, kernel_v8_lo, globalSize, localSize, iters); timed_go = run_kernel(queue, kernel_v8_go, globalSize, localSize, iters); - timed = (timed_lo < timed_go)? timed_lo: timed_go; + timed = (timed_lo < timed_go) ? timed_lo : timed_go; gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("float8", gbps); /////////////////////////////////////////////////////////////////////////// @@ -133,25 +136,32 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d timed_lo = run_kernel(queue, kernel_v16_lo, globalSize, localSize, iters); timed_go = run_kernel(queue, kernel_v16_go, globalSize, localSize, iters); - timed = (timed_lo < timed_go)? timed_lo: timed_go; + timed = (timed_lo < timed_go) ? timed_lo : timed_go; gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("float16", gbps); /////////////////////////////////////////////////////////////////////////// - log->xmlCloseTag(); // global_memory_bandwidth + log->xmlCloseTag(); // global_memory_bandwidth - if(arr) delete [] arr; + if (arr) + { + delete[] arr; + } } - catch(cl::Error &error) + catch (cl::Error &error) { stringstream ss; ss << error.what() << " (" << error.err() << ")" NEWLINE << TAB TAB TAB "Tests skipped" NEWLINE; log->print(ss.str()); - if(arr) delete [] arr; + if (arr) + { + delete[] arr; + } return -1; } diff --git a/src/kernel_latency.cpp b/src/kernel_latency.cpp index cc12af4..caebe6a 100644 --- a/src/kernel_latency.cpp +++ b/src/kernel_latency.cpp @@ -1,11 +1,10 @@ #include -#define FETCH_PER_WI 16 - +#define FETCH_PER_WI 16 int clPeak::runKernelLatency(cl::CommandQueue &queue, cl::Program &prog, device_info_t &devInfo) { - if(!isKernelLatency) + if (!isKernelLatency) return 0; cl::Context ctx = queue.getInfo(); @@ -33,7 +32,7 @@ int clPeak::runKernelLatency(cl::CommandQueue &queue, cl::Program &prog, device_ queue.finish(); latency = 0; - for(uint i=0; i(iters); - log->print(latency); log->print(" us" NEWLINE); + log->print(latency); + log->print(" us" NEWLINE); log->xmlSetContent(latency); log->xmlCloseTag(); } - catch(cl::Error &error) + catch (cl::Error &error) { stringstream ss; ss << error.what() << " (" << error.err() << ")" NEWLINE @@ -59,4 +59,3 @@ int clPeak::runKernelLatency(cl::CommandQueue &queue, cl::Program &prog, device_ return 0; } - diff --git a/src/logger.cpp b/src/logger.cpp index ef7051a..a63c6dd 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -2,10 +2,9 @@ #include #include -logger::logger(bool _enableXml, string _xmlFileName): - enableXml(_enableXml) +logger::logger(bool _enableXml, string _xmlFileName) : enableXml(_enableXml) { - if(enableXml) + if (enableXml) { xmlFile.open(_xmlFileName); xw = new xmlWriter(xmlFile); @@ -13,10 +12,9 @@ logger::logger(bool _enableXml, string _xmlFileName): } } - logger::~logger() { - if(enableXml) + if (enableXml) { xw->closeAll(); delete xw; @@ -56,10 +54,9 @@ void logger::print(unsigned int val) cout.flush(); } - void logger::xmlOpenTag(string tag) { - if(enableXml) + if (enableXml) { xw->openElt(tag.c_str()); xmlFile.flush(); @@ -68,7 +65,7 @@ void logger::xmlOpenTag(string tag) void logger::xmlAppendAttribs(string key, string value) { - if(enableXml) + if (enableXml) { xw->attr(key.c_str(), value.c_str()); xmlFile.flush(); @@ -77,7 +74,7 @@ void logger::xmlAppendAttribs(string key, string value) void logger::xmlAppendAttribs(string key, uint value) { - if(enableXml) + if (enableXml) { stringstream ss; ss << value; @@ -89,7 +86,7 @@ void logger::xmlAppendAttribs(string key, uint value) void logger::xmlSetContent(string value) { - if(enableXml) + if (enableXml) { xw->content(value.c_str()); xmlFile.flush(); @@ -98,7 +95,7 @@ void logger::xmlSetContent(string value) void logger::xmlSetContent(float value) { - if(enableXml) + if (enableXml) { stringstream ss; ss << value; @@ -110,7 +107,7 @@ void logger::xmlSetContent(float value) void logger::xmlCloseTag() { - if(enableXml) + if (enableXml) { xw->closeElt(); xmlFile.flush(); @@ -119,7 +116,7 @@ void logger::xmlCloseTag() void logger::xmlRecord(string tag, string value) { - if(enableXml) + if (enableXml) { stringstream ss; ss << value; @@ -133,7 +130,7 @@ void logger::xmlRecord(string tag, string value) void logger::xmlRecord(string tag, float value) { - if(enableXml) + if (enableXml) { stringstream ss; ss << value; diff --git a/src/logger_android.cpp b/src/logger_android.cpp index 81b4006..9b69b69 100644 --- a/src/logger_android.cpp +++ b/src/logger_android.cpp @@ -39,34 +39,43 @@ void logger::print(unsigned int val) jEnv->CallVoidMethod((*jObj), printCallback, jEnv->NewStringUTF(ss.str().c_str())); } - -logger::logger(bool _enableXml, string _xmlFileName): enableXml(false) -{} +logger::logger(bool _enableXml, string _xmlFileName) : enableXml(false) +{ +} logger::~logger() -{} +{ +} // xml dump disabled void logger::xmlOpenTag(string tag) -{} +{ +} void logger::xmlAppendAttribs(string key, string value) -{} +{ +} void logger::xmlAppendAttribs(string key, uint value) -{} +{ +} void logger::xmlSetContent(string value) -{} +{ +} void logger::xmlSetContent(float value) -{} +{ +} void logger::xmlCloseTag() -{} +{ +} void logger::xmlRecord(string tag, string value) -{} +{ +} void logger::xmlRecord(string tag, float value) -{} +{ +} diff --git a/src/options.cpp b/src/options.cpp index 1c32459..7fda134 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -1,6 +1,6 @@ #include -#define DEFAULT_XML_FILE_NAME "clpeak_results.xml" +#define DEFAULT_XML_FILE_NAME "clpeak_results.xml" static const char *helpStr = "\n clpeak [OPTIONS]" @@ -21,9 +21,7 @@ static const char *helpStr = "\n -f, --xml-file file_name specify file name for xml dump" "\n -v, --version display version" "\n -h, --help display help message" - "\n" - ; - + "\n"; int clPeak::parseArgs(int argc, char **argv) { @@ -31,104 +29,104 @@ int clPeak::parseArgs(int argc, char **argv) bool enableXml = false; string xmlFileName; - for(int i=1; iprint(helpStr); log->print(NEWLINE); + log->print(helpStr); + log->print(NEWLINE); exit(0); } - else if((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--version") == 0)) + else if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--version") == 0)) { stringstream versionStr; versionStr << "clpeak version: " << VERSION_STR; - log->print(versionStr.str().c_str()); log->print(NEWLINE); + log->print(versionStr.str().c_str()); + log->print(NEWLINE); exit(0); } - else if((strcmp(argv[i], "-p") == 0) || (strcmp(argv[i], "--platform") == 0)) + else if ((strcmp(argv[i], "-p") == 0) || (strcmp(argv[i], "--platform") == 0)) { - if((i+1) < argc) + if ((i + 1) < argc) { forcePlatform = true; - specifiedPlatform = strtoul(argv[i+1], NULL, 0); + specifiedPlatform = strtoul(argv[i + 1], NULL, 0); i++; } } - else if((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--device") == 0)) + else if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--device") == 0)) { - if((i+1) < argc) + if ((i + 1) < argc) { forceDevice = true; - specifiedDevice = strtoul(argv[i+1], NULL, 0); + specifiedDevice = strtoul(argv[i + 1], NULL, 0); i++; } } - else if(strcmp(argv[i], "--use-event-timer") == 0) + else if (strcmp(argv[i], "--use-event-timer") == 0) { useEventTimer = true; } - else if((strcmp(argv[i], "--global-bandwidth") == 0) || (strcmp(argv[i], "--compute-sp") == 0) - || (strcmp(argv[i], "--compute-dp") == 0) || (strcmp(argv[i], "--compute-integer") == 0) - || (strcmp(argv[i], "--transfer-bandwidth") == 0) || (strcmp(argv[i], "--kernel-latency") == 0)) + else if ((strcmp(argv[i], "--global-bandwidth") == 0) || (strcmp(argv[i], "--compute-sp") == 0) || (strcmp(argv[i], "--compute-dp") == 0) || (strcmp(argv[i], "--compute-integer") == 0) || (strcmp(argv[i], "--transfer-bandwidth") == 0) || (strcmp(argv[i], "--kernel-latency") == 0)) { // Disable all and enable only selected ones - if(!forcedTests) + if (!forcedTests) { isGlobalBW = isComputeSP = isComputeDP = isComputeInt = isTransferBW = isKernelLatency = false; forcedTests = true; } - if(strcmp(argv[i], "--global-bandwidth") == 0) + if (strcmp(argv[i], "--global-bandwidth") == 0) { isGlobalBW = true; } - else if(strcmp(argv[i], "--compute-sp") == 0) + else if (strcmp(argv[i], "--compute-sp") == 0) { isComputeSP = true; } - else if(strcmp(argv[i], "--compute-dp") == 0) + else if (strcmp(argv[i], "--compute-dp") == 0) { isComputeDP = true; } - else if(strcmp(argv[i], "--compute-integer") == 0) + else if (strcmp(argv[i], "--compute-integer") == 0) { isComputeInt = true; } - else if(strcmp(argv[i], "--transfer-bandwidth") == 0) + else if (strcmp(argv[i], "--transfer-bandwidth") == 0) { isTransferBW = true; } - else if(strcmp(argv[i], "--kernel-latency") == 0) + else if (strcmp(argv[i], "--kernel-latency") == 0) { isKernelLatency = true; } - } - else if(strcmp(argv[i], "--all-tests") == 0) + else if (strcmp(argv[i], "--all-tests") == 0) { isGlobalBW = isComputeSP = isComputeDP = isComputeInt = isTransferBW = isKernelLatency = true; } - else if(strcmp(argv[i], "--enable-xml-dump") == 0) + else if (strcmp(argv[i], "--enable-xml-dump") == 0) { enableXml = true; - if(xmlFileName.length() < 1) + if (xmlFileName.length() < 1) { xmlFileName = DEFAULT_XML_FILE_NAME; } } - else if((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--xml-file") == 0)) + else if ((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--xml-file") == 0)) { - if((i+1) < argc) + if ((i + 1) < argc) { enableXml = true; - xmlFileName = argv[i+1]; + xmlFileName = argv[i + 1]; i++; } } else { - log->print(helpStr); log->print(NEWLINE); + log->print(helpStr); + log->print(NEWLINE); exit(-1); } } diff --git a/src/transfer_bandwidth.cpp b/src/transfer_bandwidth.cpp index 9934b55..d1c3183 100644 --- a/src/transfer_bandwidth.cpp +++ b/src/transfer_bandwidth.cpp @@ -1,9 +1,8 @@ #include - int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, device_info_t &devInfo) { - if(!isTransferBW) + if (!isTransferBW) return 0; float timed, gbps; @@ -35,21 +34,22 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, timed = 0; - if(useEventTimer) + if (useEventTimer) { - for(uint i=0; i(iters); gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("enqueuewritebuffer", gbps); /////////////////////////////////////////////////////////////////////////// // enqueueReadBuffer @@ -70,21 +71,22 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, queue.finish(); timed = 0; - if(useEventTimer) + if (useEventTimer) { - for(uint i=0; i(iters); gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("enqueuereadbuffer", gbps); /////////////////////////////////////////////////////////////////////////// // enqueueMapBuffer @@ -103,9 +106,9 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, queue.finish(); timed = 0; - if(useEventTimer) + if (useEventTimer) { - for(uint i=0; i(iters); gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("enqueuemapbuffer", gbps); /////////////////////////////////////////////////////////////////////////// @@ -144,7 +149,7 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, queue.finish(); timed = 0; - for(uint i=0; i(iters); gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("memcpy_from_mapped_ptr", gbps); /////////////////////////////////////////////////////////////////////////// @@ -173,9 +179,9 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, queue.finish(); timed = 0; - if(useEventTimer) + if (useEventTimer) { - for(uint i=0; i(iters); gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("enqueueunmap", gbps); /////////////////////////////////////////////////////////////////////////// @@ -214,7 +222,7 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, queue.finish(); timed = 0; - for(uint i=0; i(iters); gbps = ((float)numItems * sizeof(float)) / timed / 1e3f; - log->print(gbps); log->print(NEWLINE); + log->print(gbps); + log->print(NEWLINE); log->xmlRecord("memcpy_to_mapped_ptr", gbps); /////////////////////////////////////////////////////////////////////////// - log->xmlCloseTag(); // transfer_bandwidth + log->xmlCloseTag(); // transfer_bandwidth - if(arr) delete [] arr; + if (arr) + delete[] arr; } - catch(cl::Error &error) + catch (cl::Error &error) { stringstream ss; ss << error.what() << " (" << error.err() << ")" NEWLINE << TAB TAB TAB "Tests skipped" NEWLINE; log->print(ss.str()); - if(arr) delete [] arr; + if (arr) + { + delete[] arr; + } return -1; } return 0; } -