-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Apples' Metal Performance Shaders (MPS) in pytorch (#…
…2037) * Add support for Apples' Metal Performance Shaders (MPS) in pytorch engine. * Add Unit test Co-authored-by: hrayrm <[email protected]> Co-authored-by: Frank Liu <[email protected]>
- Loading branch information
1 parent
6f68a11
commit 1d0bc77
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
engines/pytorch/pytorch-engine/src/test/java/ai/djl/pytorch/integration/MpsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance | ||
* with the License. A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
package ai.djl.pytorch.integration; | ||
|
||
import ai.djl.Device; | ||
import ai.djl.ndarray.NDArray; | ||
import ai.djl.ndarray.NDManager; | ||
import ai.djl.ndarray.types.Shape; | ||
|
||
import org.testng.Assert; | ||
import org.testng.SkipException; | ||
import org.testng.annotations.Test; | ||
|
||
public class MpsTest { | ||
|
||
@Test | ||
public void testMps() { | ||
if (!"aarch64".equals(System.getProperty("os.arch")) | ||
|| !System.getProperty("os.name").startsWith("Mac")) { | ||
throw new SkipException("MPS test requires M1 macOS."); | ||
} | ||
|
||
Device device = Device.of("mps", -1); | ||
try (NDManager manager = NDManager.newBaseManager(device)) { | ||
NDArray array = manager.zeros(new Shape(1, 2)); | ||
Assert.assertEquals(array.getDevice().getDeviceType(), "mps"); | ||
} | ||
} | ||
} |