You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that the ``torch.jit.export_opnames(optimized_model)`` is going to dump all the optimized operators from the ``optimized_mobile``. If everything works well, you should be able to see the following ops being printed out from the console
44
44
@@ -65,31 +65,34 @@ In this section, we'll be using the `HelloWorld example <https://github.com/pyto
Note ``IOS_ARCH`` tells the script to build a arm64 version of Libtorch. This is because in PyTorch, Metal is only available for the iOS devices that support the Apple A9 chip or above. Once the build finished, follow the `Build PyTorch iOS libraries from source <https://pytorch.org/mobile/ios/#build-pytorch-ios-libraries-from-source>`_ section from the iOS tutorial to setup the XCode settings properly. Don't forget to copy the `./mobilenetv2_metal.pt` to your XCode project.
68
+
Note ``IOS_ARCH`` tells the script to build a arm64 version of Libtorch. This is because in PyTorch, Metal is only available for the iOS devices that support the Apple A9 chip or above. Once the build finished, follow the `Build PyTorch iOS libraries from source <https://pytorch.org/mobile/ios/#build-pytorch-ios-libraries-from-source>`_ section from the iOS tutorial to setup the XCode settings properly. Don't forget to copy the `./mobilenetv2_metal.pt` to your XCode project and modify the model file path accordingly.
69
69
70
70
Next we need to make some changes in ``TorchModule.mm``
71
71
72
72
.. code:: objective-c
73
73
74
-
// #import <Libtorch-Lite.h>
75
-
// If it's built from source with xcode, comment out the line above
74
+
...
75
+
// #import <Libtorch-Lite/Libtorch-Lite.h>
76
+
// If it's built from source with Xcode, comment out the line above
auto outputTensor = _impl.forward({tensor}).toTensor().cpu();
85
87
...
86
88
}
89
+
...
87
90
88
91
As you can see, we simply just call ``.metal()`` to move our input tensor from CPU to GPU, and then call ``.cpu()`` to move the result back. Internally, ``.metal()`` will copy the input data from the CPU buffer to a GPU buffer with a GPU compatible memory format. When `.cpu()` is invoked, the GPU command buffer will be flushed and synced. After `forward` finished, the final result will then be copied back from the GPU buffer back to a CPU buffer.
89
92
90
-
The last step we have to do is to add the `Accelerate.framework` and the `MetalShaderPerformance.framework` to your xcode project.
93
+
The last step we have to do is to add the `Accelerate.framework` and the `MetalShaderPerformance.framework` to your xcode project. (Open your project via XCode, go to your project target’s "General" tab, locate the "Frameworks, Libraries and Embedded Content" section and click the "+" button)
91
94
92
-
If everything works fine, you should be able to see the inference results on your phone. The result below was captured from an iPhone11 device
95
+
If everything works fine, you should be able to see the inference results on your phone. The result below was captured from an iPhone 11 device
0 commit comments