Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeGenOpenCL: expect calling_conv equals CallingConv::kDeviceKernelLaunch during autotune #17577

Open
AD-lite24 opened this issue Dec 30, 2024 · 1 comment
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug

Comments

@AD-lite24
Copy link

Expected behavior

Autotune to work smoothly

Actual behavior

Autotune does not work and instead keeps throwing above errors. An instance of the error log is

('Traceback (most recent call last):\n  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/autotvm/measure/measure_methods.py", line 553, in __call__\n    func, arg_info = _build_func_common(measure_input, self.runtime, **kwargs)\n  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/autotvm/measure/measure_methods.py", line 505, in _build_func_common\n    func = build(s, args, target=target, runtime=runtime)\n  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/driver/build_module.py", line 297, in build\n    rt_mod_host = _driver_ffi.tir_to_runtime(annotated_mods, target_host)\n  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/_ffi/_ctypes/packed_func.py", line 245, in __call__\n    raise_last_ffi_error()\n  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/_ffi/base.py", line 481, in raise_last_ffi_error\n    raise py_err\ntvm.error.InternalError: Traceback (most recent call last):\n  File "/Users/adityadandwate/foss_repos/tvm/src/target/source/codegen_opencl.cc", line 651\nInternalError: Check failed: (calling_conv == CallingConv::kDeviceKernelLaunch) is false: CodeGenOpenCL: expect calling_conv equals CallingConv::kDeviceKernelLaunch\n', InternalError('Traceback (most recent call last):\n  File "/Users/adityadandwate/foss_repos/tvm/src/target/source/codegen_opencl.cc", line 651\nInternalError: Check failed: (calling_conv == CallingConv::kDeviceKernelLaunch) is false: CodeGenOpenCL: expect calling_conv equals CallingConv::kDeviceKernelLaunch'))
Traceback (most recent call last):
  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/autotvm/measure/measure_methods.py", line 553, in __call__
    func, arg_info = _build_func_common(measure_input, self.runtime, **kwargs)
  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/autotvm/measure/measure_methods.py", line 505, in _build_func_common
    func = build(s, args, target=target, runtime=runtime)
  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/driver/build_module.py", line 297, in build
    rt_mod_host = _driver_ffi.tir_to_runtime(annotated_mods, target_host)
  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/_ffi/_ctypes/packed_func.py", line 245, in __call__
    raise_last_ffi_error()
  File "/Users/adityadandwate/miniconda3/envs/tvm-run/lib/python3.10/site-packages/tvm/_ffi/base.py", line 481, in raise_last_ffi_error
    raise py_err
tvm.error.InternalError: Traceback (most recent call last):
  File "/Users/adityadandwate/foss_repos/tvm/src/target/source/codegen_opencl.cc", line 651
InternalError: Check failed: (calling_conv == CallingConv::kDeviceKernelLaunch) is false: CodeGenOpenCL: expect calling_conv equals CallingConv::kDeviceKernelLaunch

Environment

Host env: Macos
Target env: OpenCL target running ubuntu

Steps to reproduce

Same script as the tutorial https://tvm.apache.org/docs/how_to/tune_with_autotvm/tune_relay_mobile_gpu.html

@AD-lite24 AD-lite24 added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug labels Dec 30, 2024
@AD-lite24
Copy link
Author

AD-lite24 commented Jan 1, 2025

for (auto [gvar, base_func] : mod->functions) {
    ICHECK(base_func->IsInstance<PrimFuncNode>()) << "CodeGenOpenCL: Can only take PrimFunc";
    auto prim_func = Downcast<PrimFunc>(base_func);
    auto calling_conv = prim_func->GetAttr<Integer>(tvm::attr::kCallingConv);
    ICHECK(calling_conv == CallingConv::kDeviceKernelLaunch)
        << "CodeGenOpenCL: expect calling_conv equals CallingConv::kDeviceKernelLaunch";
    functions.Set(gvar, prim_func);
  }

In the pytorch conversion to IRModule, apparently the calling_conv attr was never set to kDeviceKernelLaunch, causing the check to fail. I am not sure why though, the conversion process is straightforward enough

input_data = torch.randn(input_shape)
scripted_model = torch.jit.trace(model, input_data).eval()
mod, params = relay.frontend.from_pytorch(scripted_model, shape_list)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug
Projects
None yet
Development

No branches or pull requests

1 participant