What's going to happen if not releasing kernels

I wonder if there is something bad about not releasing cl_program and cl_kernel on a gpu device. At the end of my program I do release cl_command_queue and cl_context, but I don’t release those former objects. Will this affect anything next time I use the gpu?

Nothing terrible will happen, but it’s a good practice to always clean up all resources.

Okay. Thanks. I’m just wondering if I really need to because it requires a decent amount of work to find the right place to release kernels. (I’m implementing a compiler that generate OpenCL if you wonder why it’s hard.)

If you are using C++ you may want to use smart pointers to delegate the choice of when to release the kernels.

Will using smart pointers increase the runtime of the application?

The cost of smart pointers tends to be very small. See Boost shared_ptr for example.

Not releasing CL objects will result in memory leaks. In this case, the program would leak a lot more than just the kernel-

Even though the context was released by the main program, since the kernel was not released, the retain count on the context would not be zero (the kernel has a retain on the program, which has a retain on the context), so the context would not be deallocated.

Leak until my application is terminated or until I reboot my machine?

The leak will only persist until your application is terminated. Since the case you described was at program termination I didn’t mention leaks because there will be none.