void PrepareBindingOn() { bool isMetal = IsMetal; gpuDelegate = CreateGpuDelegate(true); var options = new InterpreterOptions(); // [Metal] must be called ModifyGraphWithDelegate at beginning if (isMetal) { options.AddGpuDelegate(gpuDelegate); } interpreter = new Interpreter(FileUtil.LoadFile(fileName), options); var inputShape0 = interpreter.GetInputTensorInfo(0).shape; int height = inputShape0[1]; int width = inputShape0[2]; // int channels = inputShape0[3]; // On iOS GPU, input must be 4 channels, regardless of what model expects. int gpuInputChannels = isMetal ? 4 : 3; int gpuOutputChannels = isMetal ? 4 : 2; inputBuffer = new ComputeBuffer(height * width * gpuInputChannels, sizeof(float)); inputs = new float[height, width, gpuInputChannels]; if (!gpuDelegate.BindBufferToInputTensor(interpreter, 0, inputBuffer)) { Debug.LogError("input is not binded"); } outputBuffer = new ComputeBuffer(height * width * gpuOutputChannels, sizeof(float)); interpreter.SetAllowBufferHandleOutput(true); if (!gpuDelegate.BindBufferToOutputTensor(interpreter, 0, outputBuffer)) { Debug.LogError("output is not binded"); } // [OpenGLGLES] must be called ModifyGraphWithDelegate at last if (IsOpenGLES3) { if (interpreter.ModifyGraphWithDelegate(gpuDelegate) != Interpreter.Status.Ok) { Debug.LogError("Failed to modify the graph with delegate"); } } }
void PrepareBindingOff() { var options = new InterpreterOptions(); options.AddGpuDelegate(); interpreter = new Interpreter(FileUtil.LoadFile(fileName), options); var inputShape0 = interpreter.GetInputTensorInfo(0).shape; int height = inputShape0[1]; int width = inputShape0[2]; int channels = inputShape0[3]; inputs = new float[height, width, channels]; outputs = new float[height, width, 2]; outputBuffer = new ComputeBuffer(height * width * 2, sizeof(float)); }