halide/Halide — pull request #238 by jrprice (2014-02-20 09:30:12+00:00)
Title: GPU Module State

This pull request implements a new method of tracking the state of a GPU module in order to fix one or two issues recently raised on the mailing list.

The allocation of module state (line 227 of runtime/opencl.cpp) is never freed. I described this as a memory leak on the mailing list, but on reflection I would argue that this isn't an issue. This memory *could* be deallocated during ```halide_release()```, and then re-allocated on a subsequent call to ```halide_init_kernels()```. Instead, what happens is that the memory *isn't* deallocated, and a subsequent call to ```halide_init_kernels()``` will re-use the allocation. Since the allocated memory is never 'lost', this isn't technically a leak. We simply have a small structure of state for each distinct module, with an 'allocate-on-first-use' policy. It would be non-trivial to perform the deallocation with the current implementation anyway; simply free-ing the memory would result in the subsequent call to ```halide_init_kernels()``` being passed a non-NULL pointer to unallocated memory, which is an issue.

Feel free to disagree, but I believe this is fine the way it is.