[nnvm] error " Direct host side access to device memory...did you forget to bind?" when deploy model with target openCL

Hi all, i encounter this error when trying to deploy vgg_ssd_300 model using MXnet frontend with target openCL: “Direct host side access to device memory is detected in fuse_multibox_prior. Did you forget to bind?

Traceback (most recent call last):
File “vgg_ssd_single.py”, line 87, in
graph, lib, params = nnvm.compiler.build(nnvm_sym, target, shape_dict, params=nnvm_params)
File “/usr/local/lib/python2.7/dist-packages/nnvm-0.8.0-py2.7.egg/nnvm/compiler/build_module.py”, line 294, in build
graph = graph.apply(“GraphFusePartition”).apply(“GraphFuseCompile”)
File “/usr/local/lib/python2.7/dist-packages/nnvm-0.8.0-py2.7.egg/nnvm/graph.py”, line 234, in apply
check_call(_LIB.NNGraphApplyPasses(self.handle, npass, cpass, ctypes.byref(ghandle)))
File “/usr/local/lib/python2.7/dist-packages/nnvm-0.8.0-py2.7.egg/nnvm/_base.py”, line 75, in check_call
raise NNVMError(py_str(_LIB.NNGetLastError()))
nnvm._base.NNVMError: TVMCall CFunc Error:
Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/tvm-0.4.0-py2.7-linux-x86_64.egg/tvm/_ffi/_ctypes/function.py”, line 54, in cfun
rv = local_pyfunc(*pyargs)
File “/usr/local/lib/python2.7/dist-packages/nnvm-0.8.0-py2.7.egg/nnvm/compiler/build_module.py”, line 123, in _build
return tvm.build(funcs, target=target, target_host=target_host)
File “/usr/local/lib/python2.7/dist-packages/tvm-0.4.0-py2.7-linux-x86_64.egg/tvm/build_module.py”, line 460, in build
“Did you forget to bind?” % func.name)
ValueError: Direct host side access to device memory is detected in fuse_multibox_prior. Did you forget to bind?

i could run this model with target “llvm” and “cuda”. So, can anybody help me solve this issue?

Can you share your python script “vgg_ssd_single.py”?

Sure! here is the main part of script:

import mxnet as mx
import nnvm
import tvm
import numpy as np
from PIL import Image
from tvm.contrib import graph_runtime
import nnvm.compiler

def transform_image(image):
image = np.array(image) - np.array([123., 117., 104.])
image = image.transpose((2, 0, 1))
image = image[np.newaxis, :]
return image

image_file=‘dog.jpg’
ssd_model=‘ssd_fromcaffe_300_no_detection’
shape=300
checkpoint=0
target = ‘opencl’
ctx = tvm.context(target, 0)
dshape = (1, 3, shape, shape)
dtype = ‘float32’
threshold=0.45
class_names = [“aeroplane”, “bicycle”, “bird”, “boat”, “bottle”, “bus”, “car”, “cat”, “chair”,
“cow”, “diningtable”, “dog”, “horse”, “motorbike”, “person”, “pottedplant”,
“sheep”, “sofa”, “train”, “tvmonitor”]

mx_sym, args, auxs = mx.model.load_checkpoint(ssd_model, checkpoint)

nnvm_sym, nnvm_params = nnvm.frontend.from_mxnet(mx_sym, args, auxs)
print(‘model compiled.’)

x = transform_image(Image.open(image_file).resize((shape, shape)))
shape_dict = {‘data’: x.shape}

with nnvm.compiler.build_config(opt_level=1):
graph, lib, params = nnvm.compiler.build(nnvm_sym, target, shape_dict, params=nnvm_params)

Execute the portable graph on TVM

m = graph_runtime.create(graph, lib, ctx)
m.set_input(‘data’, tvm.nd.array(x.astype(dtype)))
m.set_input(**params)

print(‘Run…’)
m.run()

_, outshape = nnvm.compiler.graph_util.infer_shape(graph, shape={“data”: dshape})

tvm_output_0 = m.get_output(0, tvm.nd.empty(tuple(outshape[0]), ‘float32’))

[Update] this issue was fixed with lastest commit from here https://github.com/Laurawly/tvm-1 tk you very much @Laurawly

1 Like

I got the same problem with opencl target. even just running with tvm get_started.py

<class ‘tvm.tensor.Tensor’>
Traceback (most recent call last):
File “./get_started.py”, line 118, in
fadd = tvm.build(s, [A, B, C], tgt, target_host=tgt_host, name=“myadd”)
File “./tvm/python/tvm/build_module.py”, line 460, in build
“Did you forget to bind?” % func.name)
ValueError: Direct host side access to device memory is detected in myadd. Did you forget to bind?

1 Like

Hi there
Did you have resolve this issue?
Thanks

Hi @titikid , could you please explian the changes made in https://github.com/Laurawly/tvm-1 that resolved the issue.

I am facing similar error in compiling ONNX model

Traceback (most recent call last):
File “sface_nchw_trail1.py”, line 64, in
graph, lib, params = nnvm.compiler.build(sym, target, shape_dict, dtype_dict, params=params)
File “/home/ubuntu/tvm_opencl/tvm/nnvm/python/nnvm/compiler/build_module.py”, line 306, in build
graph = graph.apply(“GraphCompile”)
File “/home/ubuntu/tvm_opencl/tvm/nnvm/python/nnvm/graph.py”, line 234, in apply
check_call(_LIB.NNGraphApplyPasses(self.handle, npass, cpass, ctypes.byref(ghandle)))
File “/home/ubuntu/tvm_opencl/tvm/nnvm/python/nnvm/_base.py”, line 75, in check_call
raise NNVMError(py_str(_LIB.NNGetLastError()))
nnvm._base.NNVMError: TVMCall CFunc Error:
Traceback (most recent call last):
File “/home/ubuntu/tvm_opencl/tvm/python/tvm/_ffi/_ctypes/function.py”, line 55, in cfun
rv = local_pyfunc(*pyargs)
File “/home/ubuntu/tvm_opencl/tvm/nnvm/python/nnvm/compiler/build_module.py”, line 124, in _build
return tvm.build(funcs, target=target, target_host=target_host)
File “/home/ubuntu/tvm_opencl/tvm/python/tvm/build_module.py”, line 586, in build
fhost, mdev = _build_for_device(flist, tar, target_host)
File “/home/ubuntu/tvm_opencl/tvm/python/tvm/build_module.py”, line 415, in _build_for_device
“Did you forget to bind?” % func.name)
ValueError: Direct host side access to device memory is detected in fuse_matmul_relu. Did you forget to bind?

Did you solve this problem? I met with the same problem with opencl and get_started.py