summaryrefslogtreecommitdiff
path: root/src/opencl_mesh_kit.cpp
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2013-03-31 19:30:38 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2013-03-31 19:30:38 +0000
commit47d0dbacaab00319ef039011096a5dfacbd83618 (patch)
treeccf0c9c45e893f5f57fe8e9fcd7e3e6ea50dfb90 /src/opencl_mesh_kit.cpp
parentfd619ebcd1b38c39eb53453fe41d206d907749ff (diff)
download2013-gpudataviz-47d0dbacaab00319ef039011096a5dfacbd83618.tar.gz
2013-gpudataviz-47d0dbacaab00319ef039011096a5dfacbd83618.tar.bz2
2013-gpudataviz-47d0dbacaab00319ef039011096a5dfacbd83618.zip
Review + parsing du source pour trouver les noms des kernels à la vollée
git-svn-id: file:///var/svn/2013-gpudataviz/trunk@28 371a6b4a-a258-45f8-9dcc-bdd82ce0ac9d
Diffstat (limited to 'src/opencl_mesh_kit.cpp')
-rw-r--r--src/opencl_mesh_kit.cpp53
1 files changed, 34 insertions, 19 deletions
diff --git a/src/opencl_mesh_kit.cpp b/src/opencl_mesh_kit.cpp
index 8ad18b3..6e41c25 100644
--- a/src/opencl_mesh_kit.cpp
+++ b/src/opencl_mesh_kit.cpp
@@ -120,7 +120,7 @@ cl_int OpenCLMeshKit::initCL(intptr_t gl_display, intptr_t gl_context, intptr_t
}
-cl_int OpenCLMeshKit::compileKernels(std::list<std::string> names, const char source[], size_t sourceLen) {
+cl_int OpenCLMeshKit::compileKernels(const char source[], size_t sourceLen) {
cl_int res=0;
const char *p_source=source;
@@ -132,27 +132,43 @@ cl_int OpenCLMeshKit::compileKernels(std::list<std::string> names, const char so
}
res = clBuildProgram(program, 1, &cl_dev, "", NULL, NULL);
- if ( res!=CL_SUCCESS ) {
- std::cerr << "Failed to clBuildProgram()" << std::endl;
+ if ( res!=CL_SUCCESS ) {
+ std::cerr << "Failed to clBuildProgram()" << std::endl;
return 22;
}
- for (std::list<std::string>::iterator ii = names.begin(); ii != names.end(); ++ii) {
- std::string kName = (*ii);
- char *kNameZTS = new char[kName.length()+1];
- std::strcpy(kNameZTS, kName.c_str());
-
- cl_kernel kernel = clCreateKernel(program,kNameZTS,&res);
- delete [] kNameZTS;
-
- if ( res!=CL_SUCCESS ) {
- std::cerr << "Failed to clCreateKernel(program,\"" << kName << "\",&res);" << std::endl;
- return 23;
+ char *p_word;
+ int state=0;
+ char *source2=strdup(source); // strtok will alter the source2 string
+ char *strtok_arg1=source2;
+
+ // Trivial parsing of source to find every kernel name and register them
+ res=CL_SUCCESS;
+ while ( res == CL_SUCCESS && ( p_word=strtok(strtok_arg1, "\n\r\t (") ) != NULL ) {
+ strtok_arg1=NULL; // strtok need it's first arg NULL after the first call
+ switch(state) {
+ case 0: // Searching "__kernel"
+ if ( strcmp(p_word, "__kernel")==0 ) {
+ state=1;
+ }
+ break;
+ case 1: // Skipping kernel return type (void)
+ state=2;
+ break;
+ case 2: // Grabbing kernel name and register it
+ cl_kernel kernel = clCreateKernel(program,p_word,&res);
+ if ( res!=CL_SUCCESS ) {
+ std::cerr << "Failed to clCreateKernel(program,\""
+ << p_word << "\",&res);" << std::endl;
+ }
+ kernels[std::string(p_word)]=kernel;
+ state=0;
+ break;
}
- kernels[kName]=kernel;
}
+ delete[] source2;
- return 0;
+ return res;
}
cl_int OpenCLMeshKit::execKernel(std::string kernelName, float karg_time) {
@@ -225,8 +241,7 @@ cl_int OpenCLMeshKit::resetVBO() {
cl_int res;
std::map<std::string, cl_kernel> user_kernels=kernels;
- std::list<std::string> n; n.push_back("zero_z");
- res = compileKernels(n, kernel_src_zero_z, sizeof(kernel_src_zero_z));
+ res = compileKernels(kernel_src_zero_z, sizeof(kernel_src_zero_z));
if(res==0) res = execKernel("zero_z", 0.0f);
@@ -242,7 +257,7 @@ size_t OpenCLMeshKit::getMeshItemCount() { return this->meshWidth * this->meshHe
size_t OpenCLMeshKit::getGroupSize() { return this->groupSize; }
intptr_t OpenCLMeshKit::getGLVBO() { return this->gl_vbo; }
-void OpenCLMeshKit::setGroupSize(size_t groupSize) { this->groupSize=groupSize; }
+void OpenCLMeshKit::setGroupSize(size_t groupSize) { this->groupSize=groupSize; }
OpenCLMeshKit::~OpenCLMeshKit() { }