-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ETHOSN] Add support for non-default Ethos(TM)-N78 configurations (#9386
) - Updated tvmc with new Ethos-N78 composite target. - Added additional Ethos-N78 specific configuration options. Co-authored-by: Tristan O'Connor <tristan.oconnor@arm.com> Co-authored-by: Tristan O'Connor <tristan.oconnor@arm.com>
- Loading branch information
1 parent
541f9f2
commit 3b22607
Showing
10 changed files
with
262 additions
and
30 deletions.
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
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
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
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
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
123 changes: 123 additions & 0 deletions
123
tests/python/contrib/test_ethosn/test_partition_params.py
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,123 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License 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. | ||
"""Ethos(TM)-N partition parameter tests""" | ||
|
||
import pytest | ||
import tvm | ||
from tvm import relay | ||
import numpy as np | ||
|
||
from tvm.relay.op.contrib.ethosn import partition_for_ethosn77 | ||
from tvm.relay.op.contrib.ethosn import partition_for_ethosn78 | ||
from tvm.testing import requires_ethosn | ||
|
||
|
||
@requires_ethosn | ||
def test_ethosn78_partition_no_error(): | ||
a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8") | ||
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8")) | ||
res = relay.nn.conv2d(a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype="uint8") | ||
b = relay.var("b", shape=[8], dtype="uint8") | ||
res = relay.nn.bias_add(res, b, axis=1) | ||
|
||
mod = tvm.IRModule.from_expr(res) | ||
opts = {"variant": "Ethos-N78"} | ||
partition_for_ethosn78(mod, **opts) | ||
|
||
|
||
@requires_ethosn | ||
def test_ethosn78_partition_undefined_variant(): | ||
with pytest.raises( | ||
ValueError, match=r".*When targeting Ethos\(TM\)-N78, -variant=Ethos-N78 should be set.*" | ||
): | ||
a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8") | ||
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8")) | ||
res = relay.nn.conv2d( | ||
a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype="uint8" | ||
) | ||
b = relay.var("b", shape=[8], dtype="uint8") | ||
res = relay.nn.bias_add(res, b, axis=1) | ||
|
||
mod = tvm.IRModule.from_expr(res) | ||
partition_for_ethosn78(mod) | ||
|
||
|
||
@requires_ethosn | ||
def test_ethosn78_partition_invalid_variant(): | ||
with pytest.raises( | ||
ValueError, match=r".*When targeting Ethos\(TM\)-N78, -variant=Ethos-N78 should be set.*" | ||
): | ||
a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8") | ||
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8")) | ||
res = relay.nn.conv2d( | ||
a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype="uint8" | ||
) | ||
b = relay.var("b", shape=[8], dtype="uint8") | ||
res = relay.nn.bias_add(res, b, axis=1) | ||
|
||
mod = tvm.IRModule.from_expr(res) | ||
opts = {"variant": "Ethos-N"} | ||
partition_for_ethosn78(mod, **opts) | ||
|
||
|
||
@requires_ethosn | ||
def test_ethosn78_partition_error(): | ||
with pytest.raises( | ||
ValueError, match=r".*When targeting Ethos\(TM\)-N78, -variant=Ethos-N78 should be set.*" | ||
): | ||
a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8") | ||
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8")) | ||
res = relay.nn.conv2d( | ||
a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype="uint8" | ||
) | ||
b = relay.var("b", shape=[8], dtype="uint8") | ||
res = relay.nn.bias_add(res, b, axis=1) | ||
|
||
mod = tvm.IRModule.from_expr(res) | ||
opts = {"variant": "Ethos-N77"} | ||
partition_for_ethosn78(mod, **opts) | ||
|
||
|
||
@requires_ethosn | ||
def test_ethosn77_partition_no_error(): | ||
a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8") | ||
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8")) | ||
res = relay.nn.conv2d(a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype="uint8") | ||
b = relay.var("b", shape=[8], dtype="uint8") | ||
res = relay.nn.bias_add(res, b, axis=1) | ||
|
||
mod = tvm.IRModule.from_expr(res) | ||
partition_for_ethosn77(mod) | ||
|
||
|
||
@requires_ethosn | ||
def test_ethosn77_partition_error(): | ||
with pytest.raises( | ||
ValueError, | ||
match=r".*Setting tops, ple_ratio or sram_size has no effect when targeting Ethos\(TM\)-N77.*", | ||
): | ||
a = relay.var("a", shape=[2, 7, 8, 8], dtype="uint8") | ||
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype("uint8")) | ||
res = relay.nn.conv2d( | ||
a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype="uint8" | ||
) | ||
b = relay.var("b", shape=[8], dtype="uint8") | ||
res = relay.nn.bias_add(res, b, axis=1) | ||
|
||
mod = tvm.IRModule.from_expr(res) | ||
opts = {"tops": 4} | ||
partition_for_ethosn77(mod, **opts) |
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
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
Oops, something went wrong.