From: Pekka J. <pek...@tu...> - 2011-12-14 20:21:48
|
On 12/14/2011 08:50 PM, Erik Schnetter wrote: > I'm finding that many of the object allocation/deallocation routines are not > careful about allocation and freeing memory. I think that some reference > counting may be necessary, but this doesn't seem to be employed consistently. Ah, it seems the OpenCL specs assumes reference counting for its object types. It includes clRetain*/clRelease* functions for the OpenCL platform/runtime API struct types. I'm not sure how it's best to implement the reference counting generically in C to avoid code duplication for all the different structure types. Probably through some set of cpp macros. E.g. POCL_RELEASE(_OBJ) which decrements the ref count and if it goes to zero, frees it and POCL_RETAIN(_TYPE, _OBJ) which does the opposite. These macros then would assume the struct has a unsigned _ref_count member. Or similar. > Should we add "magic markers" into the objects, which would help identify > routines accessing objects that have been freed? I am thinking in particular of > program, kernel, and mem objects, i.e. adding such markers to their declarations > in pocl_cl.h, and checking them in various places. Valgrind should be able to spot these. In my opinion we should just run the test cases in valgrind and fix the leaks and references to the freed objects it finds instead of adding some runtime overhead (and clutter) to the code. -- --Pekka |