Comments (4)
I'm not sure I understand the problem. When a cl::Buffer
object corresponding to a sub buffer is destroyed, we call clReleaseMemObject
on the sub buffer cl_mem
, /not/ the parent buffer. In your example, when subbuf
goes out of scope, the sub buffer that it wraps will be destroyed, but the parent buffer buf
will still be valid.
Are you experiencing a problem with these APIs?
from opencl-clhpp.
The OpenCL documentation is not clear on that point, whether a subbuffer needs to be released. (Intuitively, I'd say there's no sense in releasing a subbuffer, because it owns no dedicated memory.)
Anyway, attached is an example that lets the subbuffer go out of scope before the kernel is running and then crashes with a segmentation fault (on both platforms, Clover and pocl). If I prevent the subbuffers from going out of scope (e.g. declare them static in lines 20ff., thus the destructor is not called and the memory is not released), the program runs just fine.
main.txt
(hint: I had to use .txt, because GitHub didn't let me upload a .cpp file.)
from opencl-clhpp.
I admit that It might not be crystal clear from the specification that sub-buffers should be released, but I'm afraid that is indeed the case. For example, if you look at the official OpenCL conformance tests, you can see that they call clReleaseMemObject
on sub buffer objects when they are finished with them. An example of that is here, and you can see that the parent buffer is also released a few lines later.
Intuitively, I'd say there's no sense in releasing a subbuffer, because it owns no dedicated memory.
I understand where you're coming from, but I'd think about this slightly differently. When you release a sub buffer, you're not asking the runtime to deallocate the buffer memory, you're just saying that you are done with the sub buffer object. The sub buffer object is what contains information about where the sub buffer starts and ends, what the parent buffer is, etc. Releasing this object allows the runtime to free the memory used to hold this information - but it won't deallocate the memory used for the contents of buffer until you also release the parent buffer.
The OpenCL specification says this regarding clReleaseMemObject
:
If
memobj
is a buffer object,memobj
cannot be deleted until all sub-buffer objects associated withmemobj
are deleted.
How does the runtime know when the sub buffer objects have been deleted? Because the user has called clReleaseMemObject
on them!
I hope this helps clarify things. I would certainly expect your example code to fail for the above reasons - you're destroying the sub buffer before it's used.
from opencl-clhpp.
Closing this as it was not deemed to be an issue with the headers.
from opencl-clhpp.
Related Issues (20)
- `clUnloadCompiler` is deprecated by OpenCL 1.2 HOT 2
- Question: Work on different-design-choices version of the C++ bindings? HOT 6
- enqueueMapBuffer() missing explicit command queue argument HOT 1
- Error when using external cl headers HOT 2
- Please keep releases and tags in sync HOT 4
- Trivial example fails HOT 3
- Add support for cl_command_buffer_khr
- MacOS CI builds are broken
- A curious name collision bug HOT 9
- how to handle extension API function pointers
- Semaphore support breaks compilation with clang HOT 1
- `cl_image_desc desc = {0}` is not valid C++ zero initialization. HOT 2
- Command Buffer Extension API Corner Cases HOT 1
- Naming Inconsistency for Extension Objects HOT 3
- new warning: deleting void is undefined HOT 1
- add a preprocessor enable for provisional extensions or features
- Assessment of the difficulty in porting CPU architecture for OpenCL-CLHPP
- Default values for options BUILD_EXAMPLES and BUILD_DOCS HOT 1
- clCreateCommandQueueWithProperties does not support properties like CL_QUEUE_PRIORITY_KHR CL_QUEUE_THROTTLE_KHR
- No Device-parametrized versions of compile()? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencl-clhpp.