forked from neo-ai/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BYOC][ACL] Add maximum support for float32 (apache#6506)
* ACL integration: add maximum support for float32. * Added the code generation flow in arm_compute_lib.py * Added the runtime calls in acl_runtime.cc Change-Id: I69c5522f05a46c1dd235da5d57fe499134de0425 * Add maximum to the list of supported functions Change-Id: Ia49087756be4c3ac92a3dc76fe03fb00de468f8d
- Loading branch information
Giuseppe Rossini
authored and
Tushar Dey
committed
Oct 15, 2020
1 parent
46f39b0
commit ddafcc8
Showing
4 changed files
with
132 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
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
104 changes: 104 additions & 0 deletions
104
tests/python/contrib/test_arm_compute_lib/test_maximum.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,104 @@ | ||
# 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. | ||
"""Arm Compute Library integration reshape tests.""" | ||
|
||
import numpy as np | ||
|
||
import tvm | ||
from tvm import relay | ||
|
||
from .infrastructure import ( | ||
skip_runtime_test, | ||
skip_codegen_test, | ||
build_and_run, | ||
verify, | ||
verify_codegen, | ||
) | ||
from .infrastructure import Device | ||
|
||
|
||
def _get_model(input_shape, dtype, var_names): | ||
"""Return a model and any parameters it may have.""" | ||
a = relay.var(next(var_names), shape=input_shape, dtype=dtype) | ||
b = relay.var(next(var_names), shape=input_shape, dtype=dtype) | ||
max = relay.maximum(a, b) | ||
return max | ||
|
||
|
||
def _get_expected_codegen(shape, dtype): | ||
node = { | ||
"op": "kernel", | ||
"name": "maximum", | ||
"inputs": [[0, 0, 0], [1, 0, 0]], | ||
"attrs": { | ||
"num_inputs": "2", | ||
"num_outputs": "1", | ||
"shape": [[list(shape)]], | ||
"dtype": [[dtype]], | ||
}, | ||
} | ||
|
||
inputs = [ | ||
{"op": "input", "name": "", "attrs": {"shape": [[list(shape)]], "dtype": [[dtype]]}}, | ||
{"op": "input", "name": "", "attrs": {"shape": [[list(shape)]], "dtype": [[dtype]]}}, | ||
] | ||
inputs.append(node) | ||
return inputs | ||
|
||
|
||
def test_maximum(): | ||
Device.load("test_config.json") | ||
|
||
if skip_runtime_test(): | ||
return | ||
|
||
device = Device() | ||
np.random.seed(0) | ||
|
||
for dtype, low, high, atol, rtol in [ | ||
("float32", -127, 128, 0.001, 0.001), | ||
("float32", -1, 1, 0.001, 0.001), | ||
]: | ||
inputs = { | ||
"a": tvm.nd.array(np.random.uniform(low, high, (100, 100)).astype(dtype)), | ||
"b": tvm.nd.array(np.random.uniform(low, high, (100, 100)).astype(dtype)), | ||
} | ||
outputs = [] | ||
func = _get_model(inputs["a"].shape, dtype, iter(inputs)) | ||
|
||
for acl in [False, True]: | ||
outputs.append(build_and_run(func, inputs, 1, None, device, enable_acl=acl)[0]) | ||
|
||
verify(outputs, atol=1e-7, rtol=1e-7) | ||
|
||
|
||
def test_codegen_maximum(): | ||
if skip_codegen_test(): | ||
return | ||
|
||
shape = (100, 100) | ||
inputs = {"a", "b"} | ||
for dtype in ["float32"]: | ||
args = (shape, dtype) | ||
func = _get_model(*args, iter(inputs)) | ||
exp_codegen = _get_expected_codegen(*args) | ||
verify_codegen(func, exp_codegen, 1) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_maximum() | ||
test_codegen_maximum() |