ekalda commented on a change in pull request #9457:
URL: https://github.com/apache/tvm/pull/9457#discussion_r750119977



##########
File path: tests/python/contrib/test_ethosu/test_codegen.py
##########
@@ -343,5 +343,178 @@ def representative_dataset():
     infra.verify_source(compiled_models, accel_type)
 
 
[email protected]("accel_type", ACCEL_TYPES)
[email protected]("ifm_shape", [(3, 2), (1, 15, 11, 7), (3, 1, 12), 
(400,)])
[email protected]("ifm_scale, ifm_zp, ofm_scale, ofm_zp", [(1, 0, 1, 
0), (0.015, 3, 0.2, 5)])
+def test_ethosu_identity_codegen(ifm_shape, ifm_scale, ifm_zp, ofm_scale, 
ofm_zp, accel_type):
+    # Create a "partitioned" Relay function
+    ifm = relay.var("ifm", shape=ifm_shape, dtype="int8")
+    ifm0 = relay.var("ifm0", shape=ifm_shape, dtype="int8")
+    identity = infra.make_ethosu_identity(
+        ifm0, ifm_scale=ifm_scale, ifm_zero_point=ifm_zp, ofm_scale=ofm_scale, 
ofm_zero_point=ofm_zp
+    )
+    glb_ethosu = relay.GlobalVar("tvmgen_default_ethosu_main_0")
+
+    func = (
+        relay.Function([ifm0], identity)
+        .with_attr("Inline", 1)
+        .with_attr("Compiler", "ethosu")
+        .with_attr("global_symbol", "tvmgen_default_ethosu_main_0")
+        .with_attr("Primitive", 1)
+    )
+    mod = tvm.IRModule()
+    mod[glb_ethosu] = func
+    mod = relay.transform.InferType()(mod)
+
+    call = relay.Call(glb_ethosu, [ifm])
+    mod["main"] = relay.Function([ifm], call)
+    mod = relay.transform.InferType()(mod)
+
+    in_data = np.random.randint(-120, high=120, size=ifm_shape, dtype="int8")
+    requant_data = (ifm_scale * (in_data - ifm_zp)) / ofm_scale + ofm_zp
+    out_data = np.round(np.clip(requant_data, -128, 127)).astype("int8")
+
+    compiled_model = infra.build_source(
+        mod, {"ifm": in_data}, [out_data], accel_type, output_tolerance=1
+    )
+
+    imported_modules = compiled_model[0].executor_factory.lib.imported_modules
+    assert len(imported_modules) == 2
+    ethosu_module = imported_modules[0]
+
+    # Verify generated C source
+    get_cs = tvm._ffi.get_global_func("runtime.module.ethosu.getcs")
+    cmms = get_cs(ethosu_module)
+    cmms = bytes.fromhex(cmms)
+
+    infra.print_payload(cmms)
+    infra.verify_source(compiled_model, accel_type)
+
+
[email protected]("accel_type", ACCEL_TYPES)
[email protected](

Review comment:
       Done

##########
File path: tests/python/contrib/test_ethosu/test_codegen.py
##########
@@ -343,5 +343,178 @@ def representative_dataset():
     infra.verify_source(compiled_models, accel_type)
 
 
[email protected]("accel_type", ACCEL_TYPES)
[email protected]("ifm_shape", [(3, 2), (1, 15, 11, 7), (3, 1, 12), 
(400,)])
[email protected]("ifm_scale, ifm_zp, ofm_scale, ofm_zp", [(1, 0, 1, 
0), (0.015, 3, 0.2, 5)])
+def test_ethosu_identity_codegen(ifm_shape, ifm_scale, ifm_zp, ofm_scale, 
ofm_zp, accel_type):
+    # Create a "partitioned" Relay function
+    ifm = relay.var("ifm", shape=ifm_shape, dtype="int8")
+    ifm0 = relay.var("ifm0", shape=ifm_shape, dtype="int8")
+    identity = infra.make_ethosu_identity(
+        ifm0, ifm_scale=ifm_scale, ifm_zero_point=ifm_zp, ofm_scale=ofm_scale, 
ofm_zero_point=ofm_zp
+    )
+    glb_ethosu = relay.GlobalVar("tvmgen_default_ethosu_main_0")
+
+    func = (
+        relay.Function([ifm0], identity)
+        .with_attr("Inline", 1)
+        .with_attr("Compiler", "ethosu")
+        .with_attr("global_symbol", "tvmgen_default_ethosu_main_0")
+        .with_attr("Primitive", 1)
+    )
+    mod = tvm.IRModule()
+    mod[glb_ethosu] = func
+    mod = relay.transform.InferType()(mod)
+
+    call = relay.Call(glb_ethosu, [ifm])
+    mod["main"] = relay.Function([ifm], call)
+    mod = relay.transform.InferType()(mod)
+
+    in_data = np.random.randint(-120, high=120, size=ifm_shape, dtype="int8")
+    requant_data = (ifm_scale * (in_data - ifm_zp)) / ofm_scale + ofm_zp
+    out_data = np.round(np.clip(requant_data, -128, 127)).astype("int8")
+
+    compiled_model = infra.build_source(
+        mod, {"ifm": in_data}, [out_data], accel_type, output_tolerance=1
+    )
+
+    imported_modules = compiled_model[0].executor_factory.lib.imported_modules
+    assert len(imported_modules) == 2
+    ethosu_module = imported_modules[0]
+
+    # Verify generated C source
+    get_cs = tvm._ffi.get_global_func("runtime.module.ethosu.getcs")
+    cmms = get_cs(ethosu_module)
+    cmms = bytes.fromhex(cmms)
+
+    infra.print_payload(cmms)
+    infra.verify_source(compiled_model, accel_type)
+
+
[email protected]("accel_type", ACCEL_TYPES)
[email protected](
+    "ifm_shape, new_shape",
+    [
+        ((1, 4, 1, 2), (1, 1, 1, 8)),
+        (
+            (
+                5,
+                1,
+                20,
+            ),
+            (1, 5, 1, 20),
+        ),
+        ((12, 20), (1, 6, 4, 10)),
+        ((12, 20), (6, 4, 10)),
+        ((20,), (4, 5)),
+    ],
+)
+def test_relay_reshape_codegen(ifm_shape, new_shape, accel_type):
+    # Create a "partitioned" Relay graph

Review comment:
       Done




-- 
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]


Reply via email to