Skip to content

Commit

Permalink
[Hexagon] Switch from default_rng to random in Hexagon tests (apache#…
Browse files Browse the repository at this point in the history
…13616)

default_rng was introduced in numpy 1.19, which is not present
even in Ubuntu 20.04 (it comes with 1.17.4).
  • Loading branch information
Krzysztof Parzyszek authored and fzi-peccia committed Mar 27, 2023
1 parent f566e61 commit 69e3509
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
6 changes: 2 additions & 4 deletions tests/python/contrib/test_hexagon/test_parallel_hvx.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
Test parallelizing HVX workloads and compare them to single thread examples.
"""
import numpy as np
from numpy.random import default_rng

import tvm
from tvm.script import tir as T
Expand Down Expand Up @@ -148,9 +147,8 @@ def evaluate(hexagon_session, shape_dtypes, expected_output_producer, sch):
func_tir = tvm.build(sch.mod["main"], target=get_hexagon_target("v68"))
module = hexagon_session.load_module(func_tir)

rng = default_rng()
a = rng.integers(0, 16, a_shape, dtype=a_dtype)
b = rng.integers(0, 16, b_shape, dtype=b_dtype)
a = np.random.randint(0, 16, a_shape, dtype=a_dtype)
b = np.random.randint(0, 16, b_shape, dtype=b_dtype)
c = np.zeros(c_shape, dtype=c_dtype)

a_hexagon = tvm.runtime.ndarray.array(a, device=hexagon_session.device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import numpy as np
import tvm
from numpy.random import default_rng
from tvm.script import tir as T

from .infrastructure import get_hexagon_target
Expand Down Expand Up @@ -395,11 +394,11 @@ class TestMatMulVec:

@tvm.testing.fixture
def input_a(self, operations):
return default_rng().integers(0, 16, (operations, 128), dtype="uint8")
return np.random.randint(0, 16, (operations, 128), dtype="uint8")

@tvm.testing.fixture
def input_b(self, operations):
return default_rng().integers(0, 16, (operations, 128), dtype="uint8")
return np.random.randint(0, 16, (operations, 128), dtype="uint8")

@tvm.testing.fixture
def input_c(self, operations):
Expand Down
8 changes: 4 additions & 4 deletions tests/python/contrib/test_hexagon/test_parallel_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
""" Test parallelism for multiple different scalar workloads. """

import numpy as np
from numpy.random import default_rng

import tvm
from tvm.script import tir as T
Expand Down Expand Up @@ -91,9 +90,10 @@ def evaluate(hexagon_session, operations, expected, sch):
func_tir = tvm.build(sch.mod["main"], target=get_hexagon_target("v68"))
module = hexagon_session.load_module(func_tir)

rng = default_rng()
a = rng.random(shape, dtype=dtype)
b = rng.random(shape, dtype=dtype)
# np.random.random returns float64 by default, but make the cast explicit
# to make it easier to switch when necessary.
a = np.random.random(shape).astype(dtype)
b = np.random.random(shape).astype(dtype)
c = np.zeros(shape, dtype=dtype)

a_hexagon = tvm.runtime.ndarray.array(a, device=hexagon_session.device)
Expand Down
4 changes: 1 addition & 3 deletions tests/python/contrib/test_hexagon/test_vtcm_bandwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"""Test theoretical bandwith for data transfers to VTCM for different strategies."""

import numpy as np
from numpy.random import default_rng

import tvm
from tvm.script import tir as T
Expand Down Expand Up @@ -96,8 +95,7 @@ def evaluate(hexagon_session, sch, size):
func_tir = tvm.build(sch.mod["main"], target=get_hexagon_target("v69"))
module = hexagon_session.load_module(func_tir)

rng = default_rng()
a = rng.integers(-128, 127, a_shape, dtype="int8")
a = np.random.randint(-128, 127, a_shape, dtype="int8")
a_vtcm = np.zeros(a_shape, dtype="int8")

a_hexagon = tvm.runtime.ndarray.array(a, device=hexagon_session.device, mem_scope="global")
Expand Down

0 comments on commit 69e3509

Please sign in to comment.