I am writing an object recognition program. I am using Metal Api.The problem is that i need array list or dynamic array, but there is no dynamic array in Metal. Is there a way to declare one or to implement your own?
Asked
Active
Viewed 841 times
2
-
3No, Metal is very memory strict. It can't handle stuff with an undefined amount of memory. Buffers can be used as semi dynamic arrays. If you can figure out the max size of the array on the cpu side, just create a buffer of that size. More on the why [here](http://stackoverflow.com/questions/32193726/newcomputepipelinestatewithfunction-failed) – R Menke Nov 02 '15 at 11:44
1 Answers
1
There is no way to do dynamic memory allocation inside the Metal kernels (shaders). I'd just define more buffers on the CPU side and pass it to the shader (instead of creating dynamic arrays inside the shaders). Just make sure to change the 'storage mode' to 'private' for the buffers you want to use just in the shader for the intermediate calculations. The 'private' mode mean the buffer is just on the GPU and CPU does not have access to it (and can reduce overhead).

Elaheh Sadredini
- 11
- 2