Skip to content

Commit

Permalink
clip test case updated (apache#59)
Browse files Browse the repository at this point in the history
Test case for clip layer added
  • Loading branch information
HV, Jayashree authored and srkreddy1238 committed Aug 8, 2024
1 parent ac1f6ff commit 9b0581c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/python/contrib/test_clml/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,5 +1313,50 @@ def _verify(out, params, inputs):
_verify(*(_get_model((1, 128, 4, 4))))


@pytest.mark.parametrize("dtype", ["float16", "float32"])
@pytest.mark.parametrize(
"trials",
[
[(1, 32, 256, 256), -1, 1],
[(1, 8, 64, 64), 0, 1],
],
)
@tvm.testing.requires_openclml
@tvm.testing.parametrize_targets("opencl -device=adreno")
def test_clip(remote, dtype, target, executor_type, trials):
def _verify(shape, a_min, a_max):
np.random.seed(0)
a = relay.var("a", shape=(shape), dtype=dtype)
out = relay.clip(a, a_min, a_max)
inputs = {"a": tvm.nd.array(np.random.uniform(-1, 1, shape).astype(dtype))}
params = {}
mod = IRModule.from_expr(out)
outputs = _build_and_run_network(remote, mod, params, inputs, target, executor_type)
out_tol = 1e-3 if dtype == "float16" else 1e-5
tvm.testing.assert_allclose(
outputs[0].asnumpy(), outputs[1].asnumpy(), rtol=out_tol, atol=out_tol
)
exp_codegen = [
{"attrs": {"dtype": [[dtype]], "shape": [[shape]]}, "name": "", "op": "input"},
{
"attrs": {
"a_max": [[str(a_max)]],
"a_min": [[str(a_min)]],
"dtype": [[dtype]],
"num_inputs": "1",
"num_outputs": "1",
"shape": [[shape]],
},
"inputs": [[0, 0, 0]],
"name": "clip",
"op": "kernel",
},
]

verify_codegen(remote, mod, params, exp_codegen, target)

_verify(trials[0], trials[1], trials[2])


if __name__ == "__main__":
tvm.testing.main()

0 comments on commit 9b0581c

Please sign in to comment.