I’m currently migrating a small function with 3D array do “sqrtf” calculation function from C language based to **GPU computation way**(By using Metal Shade Language buffer & commits small funct process to GPU). But problem is how should I manage the commit and buffer every times small calculation function got called in CPU multi thread.
Here’s a rough n simple pseudo code sample :
sample code of implementing gpu funct in cpu multiThreads funct
My Questions:
1)How to manager Metal variables data such as Mtldevice, MTL Buffer, MTLPipeline. (If I’m not mistaken All These preps actions & datas shouldn’t be re-initialize whenever CalculateDistanceBetween2P() got called in Each CPU Threads.)
- When do I place the commit() Metal command will be most suitable. Because I tried committ() in 8 CPU Threads at the same time running parallel.
The Outcome: 6 Threads return are fine (correct value) Distance value
BUT **2 Threads failed **by return Distance = 0 value
3)Any sample code of similar situation in objC , Metal?
Thanks in advance world peeps