clray

diff src/ocl.cc @ 40:1bcbb53b3505

segfault on exit?
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 Aug 2010 19:00:14 +0100
parents 980bc07be868
children 057b8575a1c1
line diff
     1.1 --- a/src/ocl.cc	Fri Aug 27 18:30:09 2010 +0100
     1.2 +++ b/src/ocl.cc	Fri Aug 27 19:00:14 2010 +0100
     1.3 @@ -53,6 +53,11 @@
     1.4  		return false;
     1.5  	}
     1.6  
     1.7 +#ifndef CLGL_INTEROP
     1.8 +	cl_context_properties *prop = 0;
     1.9 +
    1.10 +#else
    1.11 +
    1.12  #if defined(__APPLE__)
    1.13  #error "CL/GL context sharing not implemented on MacOSX yet"
    1.14  #elif defined(unix) || defined(__unix__)
    1.15 @@ -72,6 +77,8 @@
    1.16  #error "unknown or unsupported platform"
    1.17  #endif
    1.18  
    1.19 +#endif	/* CLGL_INTEROP */
    1.20 +
    1.21  	if(!(ctx = clCreateContext(prop, 1, &devinf.id, 0, 0, 0))) {
    1.22  		fprintf(stderr, "failed to create opencl context\n");
    1.23  		return false;
    1.24 @@ -84,6 +91,19 @@
    1.25  	return true;
    1.26  }
    1.27  
    1.28 +void destroy_opencl()
    1.29 +{
    1.30 +	if(cmdq) {
    1.31 +		clReleaseCommandQueue(cmdq);
    1.32 +		cmdq = 0;
    1.33 +	}
    1.34 +
    1.35 +	if(ctx) {
    1.36 +		clReleaseContext(ctx);
    1.37 +		ctx = 0;
    1.38 +	}
    1.39 +}
    1.40 +
    1.41  
    1.42  CLMemBuffer *create_mem_buffer(int rdwr, size_t sz, const void *buf)
    1.43  {
    1.44 @@ -238,15 +258,14 @@
    1.45  		clReleaseEvent(wait_event);
    1.46  	}
    1.47  	if(last_event) {
    1.48 +		clWaitForEvents(1, &last_event);
    1.49  		clReleaseEvent(last_event);
    1.50  	}
    1.51  
    1.52  	if(prog) {
    1.53 -
    1.54  		clReleaseProgram(prog);
    1.55  	}
    1.56  	if(kernel) {
    1.57 -
    1.58  		clReleaseKernel(kernel);
    1.59  	}
    1.60  	for(size_t i=0; i<args.size(); i++) {
    1.61 @@ -449,12 +468,6 @@
    1.62  
    1.63  bool CLProgram::run(int dim, ...) const
    1.64  {
    1.65 -	if(!built) {
    1.66 -		if(!((CLProgram*)this)->build()) {
    1.67 -			return false;
    1.68 -		}
    1.69 -	}
    1.70 -
    1.71  	va_list ap;
    1.72  	size_t *global_size = (size_t*)alloca(dim * sizeof *global_size);
    1.73