lhutton1 commented on code in PR #13212: URL: https://github.com/apache/tvm/pull/13212#discussion_r1145964962
########## python/tvm/relay/analysis/operations_distribution.py: ########## @@ -0,0 +1,86 @@ +# 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. +"""Utilities that enable analyze Relay and get mappings for unique +input module layer name to the tuple of compiler and operation name""" +import tvm +from tvm import relay +from tvm.relay.expr_functor import ExprVisitor + + +class AnalyzeOperationsDistribution(ExprVisitor): Review Comment: nit: did a generic only test get added? ########## tests/python/driver/tvmc/test_compiler.py: ########## @@ -49,6 +51,355 @@ def test_save_dumps(tmpdir_factory): assert path.exists("{}/{}".format(tmpdir, "fake_module.relay")) +def test_save_dump_offloads_ethosu(tmp_path_factory): + + tflite = pytest.importorskip("tflite") + tensorflow = pytest.importorskip("tensorflow") + pytest.importorskip("ethosu.vela") + + import tensorflow as tf + import tflite.Model + from tvm.driver.tvmc.model import TVMCModel + + inp = (224, 224, 9) + input_shape = (1, *inp) + kernel_shape = (3, 3) + padding = (1, 1, 1, 1) + padding_out = (1, 33, 33, 1) + + @tf.function + def simple_net(x): + weight_shape = [kernel_shape[0], kernel_shape[1], input_shape[3], 3] + weights = tf.constant(np.random.uniform(size=weight_shape), dtype=tf.float32) + weight_shape[2] = 3 + weights1 = tf.constant(np.random.uniform(size=weight_shape), dtype=tf.float32) + weights2 = tf.constant(np.random.uniform(size=weight_shape), dtype=tf.float32) + op = tf.nn.conv2d( + x, + filters=weights, + strides=1, + padding="SAME", + data_format="NHWC", + dilations=1, + ) + op1 = tf.nn.conv2d( + op, + filters=weights1, + strides=1, + padding="SAME", + data_format="NHWC", + dilations=1, + ) + op2 = tf.nn.conv2d( + op, + filters=weights2, + strides=1, + padding="SAME", + data_format="NHWC", + dilations=1, + ) + op = tf.math.add(op1, op2) + op = tf.pad( + op, + [[0, 0], [padding[0], padding_out[1]], [padding_out[2], padding[3]], [0, 0]], + "CONSTANT", + ) + return op + + from tests.python.contrib.test_ethosu.infra import get_tflite_graph + + _, tflite_graph = get_tflite_graph(simple_net, [input_shape]) + tflite_model = tflite.Model.Model.GetRootAsModel(tflite_graph, 0) + mod, params = relay.frontend.from_tflite(tflite_model) + + tvmc_model = TVMCModel(mod, params) + + output_dir = tmp_path_factory.mktemp("tmp") + output_file_name = os.path.join(str(output_dir), "list.txt") + + tvmc.compiler.compile_model( + tvmc_model, + target="ethos-u,cmsis-nn,c", + runtime=Runtime("crt"), + tuning_records="", + package_path="module.tar", + executor=Executor("aot", {"unpacked-api": 1, "interface-api": "c", "link-params": True}), + cross="", + cross_options="", + output_format="mlf", + dump_offloads=output_file_name, + disabled_pass=[""], + pass_context_configs=[ + "tir.disable_vectorize=1", + "tir.usmp.enable=1", + "tir.usmp.algorithm=hill_climb", + "tir.disable_storage_rewrite=1", + "relay.frontend.fill_span=1", + ], + additional_target_options={ + "c": {"mcpu": "cortex-m55"}, + "cmsis-nn": {"mcpu": "cortex-m55"}, + "ethos-u": { + "accelerator_config": "ethos-u55-256", + }, + }, + ) + + expected = [ + r"Total number of operators and distribution by targets", + r"Total: 11", + r"ethos-u: 10", + r"generic: 1", Review Comment: I didn't notice this before, looks good :) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
