Unity-Technologies / barracuda-release

Other
561 stars 76 forks source link

ArgumentException: Kernel TextureToTensor and TextureToTensor_NHWC are both missing at Unity.Barracuda.ComputeFunc..ctor #279

Open aaronvdbrugge opened 2 years ago

aaronvdbrugge commented 2 years ago

PixelShader is giving me issues in FireFox (please see the other ticket I posted, I do need help with that) so meanwhile I was examining using a CPU WorkerType with older Barracuda.

I am now using CSharp WorkerType and Barracuda 1.0.0 with Unity 2022.1.0b16 for WebGL.

I get this error:

ArgumentException: Kernel TextureToTensor and TextureToTensor_NHWC are both missing
  at Unity.Barracuda.ComputeFunc..ctor 

On this line:

yield return _worker.StartManualSchedule(inputs);

I am looking into turning the pixels of a Texture2D into srcData float[] but am not sure what the recommended function to do this is?

aaronvdbrugge commented 2 years ago

I got up to here:

   float[] DecodeFloatTexture()
    {
        Texture2D decTex = new Texture2D(InputImageSize, InputImageSize, TextureFormat.RGBAFloat, false);
        //RenderTexture.active = new RenderTexture(InputImageSize, InputImageSize, 16, RenderTextureFormat.ARGB32);

        RenderTexture rt = new RenderTexture(InitImg.width, InitImg.height, 0);
        RenderTexture.active = rt;
        // Copy your texture ref to the render texture
        Graphics.Blit(InitImg, rt);

        decTex.ReadPixels(new Rect(0, 0, InputImageSize, InputImageSize), 0, 0);
        decTex.Apply();

        RenderTexture.active = null;
        Color[] colors = decTex.GetPixels();
        float[] results = new float[colors.Length*3];

        for(int i=0; i<colors.Length; i++)
        {
            results[i * 3] = colors[i].r;
            results[i * 3 + 1] = colors[i].g;
            results[i * 3 + 2] = colors[i].b;
        }
        return results;
    }

and

        inputs[inputName_1] = new Tensor(1, InputImageSize, InputImageSize, 3, DecodeFloatTexture(), "");
        inputs[inputName_2] = new Tensor(1, InputImageSize, InputImageSize, 3, DecodeFloatTexture(), "");
        inputs[inputName_3] = new Tensor(1, InputImageSize, InputImageSize, 3, DecodeFloatTexture(), "");

        // Create input and Execute model
        yield return _worker.StartManualSchedule(inputs);

But the resulting error is:

DllNotFoundException: macblas assembly:<unknown assembly> type:<unknown type> member:(null)
Unity.Barracuda.MacBLAS.SGEMM (System.Single* Ap, System.Int32 AN, System.Int32 AM, System.Single* Bp, System.Int32 BN, System.Int32 BM, System.Single* Cp, System.Int32 CN, System.Int32 CM, System.Int32 bs, System.Boolean transposeA, System.Boolean transposeB) (at Library/PackageCache/com.unity.barracuda@1.0.0/Barracuda/Runtime/Plugins/OSX/MacBLAS.cs:39)
Unity.Barracuda.UnsafeArrayCPUOps.Conv2DUsingIm2ColSliced (Unity.Barracuda.Tensor X, Unity.Barracuda.Tensor K, Unity.Barracuda.Tensor B, System.Int32[] stride, System.Int32[] pad) (at Library/PackageCache/com.unity.barracuda@1.0.0/Barracuda/Runtime/Core/Backends/BarracudaUnsafeArrayCPU.cs:1456)

So, I'm pretty sure I am still off here.