wangzy0327 commented on issue #13666:
URL: https://github.com/apache/tvm/issues/13666#issuecomment-1413075362
@masahi Hi,I have tried to fix the code as #13847 and run the code on
gfx908(MI100)
<summary>onnx_rocm.py</summary>
```
from pyexpat import model
import onnx
#from tvm.driver import tvmc
import numpy as np
import tvm
import tvm.relay as relay
from tvm.contrib import graph_executor
import tvm.testing
import numpy as np
dtype="float32"
common_prefix_str = "onnx-model/vision/classification/"
tol_paras = [1e-7,1e-6,1e-5,1e-4,1e-3,1e-2]
input_name = "Input3"
input_size = (1,1,28,28)
output_size = (1,10)
import logging
logging.basicConfig(level=logging.ERROR)
import warnings
warnings.filterwarnings('ignore')
def build(target:str,mod:tvm.IRModule, params:dict, input_name:str,
input_data:np.ndarray, input:tuple, output: tuple) -> np.ndarray:
tgt = tvm.target.Target(target=target, host="llvm")
with tvm.transform.PassContext(opt_level=3):
lib = relay.build(mod, target=target, params=params)
dev = tvm.device(str(target), 0)
module = graph_executor.GraphModule(lib["default"](dev))
module.set_input(input_name, input_data)
module.run()
output_shape = output
tvm_output = module.get_output(0, tvm.nd.empty(output_shape)).numpy()
return tvm_output
def main():
np.random.seed(0)
I_np = np.random.uniform(size = input_size).astype(dtype)
print(I_np[0][0][0][:10])
onnx_model =
onnx.load("onnx-model/vision/classification/mnist/model/mnist-7.onnx")
mod,params = relay.frontend.from_onnx(onnx_model,{"Input3":I_np.shape})
rocm_output = build("rocm",mod = mod,params = params,input_name =
input_name,input_data = I_np, input = I_np.shape, output = output_size)
opencl_output = build("opencl",mod = mod,params = params,input_name =
input_name,input_data = I_np, input = I_np.shape, output = output_size)
print(rocm_output[0][:10])
print(opencl_output[0][:10])
main()
```
The result as follows:

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