c++ - newComputePipelineStateWithFunction failed -
i trying let neural net run on metal. basic idea of data duplication. each gpu thread runs 1 version of net random data points.
i have written other shaders work fine.
i tried code in c++ command line app. no errors there. there no compile error.
i used apple documentation convert metal c++, since not c++11 supported.
it crashes after loads kernel function , when tries assign newcomputepipelinestatewithfunction
metal device. means there problem code isn't caught @ compile time.
mcve:
kernel void net(const device float *inputsvector [[ buffer(0) ]], // layout of net * uint id [[ thread_position_in_grid ]]) { uint floatsize = sizeof(tempfloat); uint inputsvectorsize = sizeof(inputsvector) / floatsize; float newarray[inputsvectorsize]; float test = inputsvector[id]; newarray[id] = test; }
update
it has dynamic arrays.
since fails create pipeline state , doesn't crash running actual shader must coding issue. not input issue.
assigning values dynamic array buffer makes fail.
the real problem: it memory issue!
to people saying memory issue, right! here pseudo code illustrate it. sorry in "swift" easier read. metal shaders have funky way of coming life. first initialised without values memory. step failed because relied on later step: setting buffer.
it comes down values available when. understanding of newcomputepipelinestatewithfunction
wrong. not getting shader function. tiny step in initialising process.
class metalshader { // buffers var abuffer : [float] var abuffercount : int // step 1 : newcomputepipelinestatewithfunction memory init() { // assign shader memory // create memory 1 int let astaticvalue : int // create memory 1 int var anotsostaticvalue : int // wil succeed, assigns memory 1 int // create memory 10 floats var astaticarray : [float] = [float](count: astaticvalue, repeatedvalue: y) // succeed // create memory x floats var adynamicarray : [float] = [float](count: abuffer.count, repeatedvalue: y) // fail var adynamicarray : [float] = [float](count: abuffercount, repeatedvalue: y) // fail let tempvalue : float // 1 float loop } // step 2 : commandencoder.setbuffer() assign buffers (buffers) { abuffer = cpumemorybuffer } // step 3 : commandencoder.endencoding() actual init() { // set shader values let astaticvalue : int = 0 var anotsostaticvalue : int = abuffer.count var adynamicarray : [float] = [float](count: abuffer.count, repeatedvalue: 1) // work, app crashed before getting point. } // step 4 : commandbuffer.commit() func shaderfunction() { // stuff in 0..<abuffer.count { let tempvalue = abuffer[i] } } }
fix:
i realised buffers technically dynamic arrays , instead of creating arrays inside shader, add more buffers. works.
Comments
Post a Comment