krrishnarraj / clpeak

A tool which profiles OpenCL devices to find their peak capacities
Apache License 2.0
407 stars 114 forks source link

Outputting to file makes bad text files #39

Closed hjmallon closed 5 years ago

hjmallon commented 7 years ago

./clpeak > output.txt

This makes bad output files as the functions like "platforms[p].getInfo()" seems to give ['A', 'p', 'p', 'l', 'e', '\0'] rather than ['A', 'p', 'p', 'l', 'e']. If I try to change cl.hpp to cl2.hpp then this problem is fixed. I didn't want to submit a pull request as I have only tested on macOS and it works when building with Xcode but CMAKE_BUILD_TYPE=Debug and building with make returns "Release Object (-34)" adn I haven't got that working yet.

diff --git a/include/clpeak.h b/include/clpeak.h
index 1d4c59f..156dc57 100644
--- a/include/clpeak.h
+++ b/include/clpeak.h
@@ -1,9 +1,10 @@
 #ifndef CLPEAK_HPP
 #define CLPEAK_HPP

-#define __CL_ENABLE_EXCEPTIONS
-
-#include <CL/cl.hpp>
+#define CL_HPP_ENABLE_EXCEPTIONS
+#define CL_HPP_MINIMUM_OPENCL_VERSION 100
+#define CL_HPP_TARGET_OPENCL_VERSION 100
+#include <CL/cl2.hpp>

 #include <iostream>
 #include <stdio.h>
diff --git a/src/clpeak.cpp b/src/clpeak.cpp
index 273447a..e44d085 100644
--- a/src/clpeak.cpp
+++ b/src/clpeak.cpp
@@ -2,7 +2,7 @@

 #define MSTRINGIFY(...) #__VA_ARGS__

-static const char *stringifiedKernels =
+static const string stringifiedKernels =
     #include "global_bandwidth_kernels.cl"
     #include "compute_sp_kernels.cl"
     #include "compute_hp_kernels.cl"
@@ -10,7 +10,7 @@ static const char *stringifiedKernels =
     #include "compute_integer_kernels.cl"
     ;

-static const char *stringifiedKernelsNoInt =
+static const string stringifiedKernelsNoInt =
     #include "global_bandwidth_kernels.cl"
     #include "compute_sp_kernels.cl"
     #include "compute_hp_kernels.cl"
@@ -83,13 +84,13 @@ int clPeak::runAll()
       // Causes Segmentation fault: 11
       if(isIntel || isApple)
       {
-        cl::Program::Sources source(1, make_pair(stringifiedKernelsNoInt, (strlen(stringifiedKernelsNoInt)+1)));
+        cl::Program::Sources source(1, stringifiedKernelsNoInt);
         isComputeInt = false;
         prog = cl::Program(ctx, source);
       }
       else
       {
-        cl::Program::Sources source(1, make_pair(stringifiedKernels, (strlen(stringifiedKernels)+1)));
+        cl::Program::Sources source(1, stringifiedKernels);
         prog = cl::Program(ctx, source);
       }