# USE\_LIBTORCH build fail for 0.9

**URL:** <https://discuss.tvm.apache.org/t/use-libtorch-build-fail-for-0-9/13319>\
**Category:** Troubleshooting\
**Created:** [August 14, 2022, 1:38am UTC](https://discuss.tvm.apache.org/t/use-libtorch-build-fail-for-0-9/13319 "2022-08-14T01:38:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leiwen83](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/leiwen83/32/3991_2.png) [@leiwen83](https://discuss.tvm.apache.org/u/leiwen83)\
**Post date:** [August 14, 2022, 1:38am UTC](https://discuss.tvm.apache.org/t/use-libtorch-build-fail-for-0-9/13319/1 "2022-08-14T01:38:24Z")

</div>

Hi,

I try on enable USE\_LIBTORCH in 0.9, but got below error msg. Which version of pytorch is verified, and is there special step to enable it?

```auto
In file included from /data/qtensor/tvm/src/runtime/contrib/libtorch/libtorch_runtime.cc:33:
/usr/local/include/ATen/DLConvertor.h:17:11: error: ‘DLContext’ does not name a type; did you mean ‘Context’?
   17 | TORCH_API DLContext getDLContext(const Tensor& tensor, const int64_t& device_id);
      | ^ ~~~~~~~~
      | Context
In file included from /data/qtensor/tvm/include/tvm/tir/usmp/utils.h:30,
                 from /data/qtensor/tvm/src/relay/backend/contrib/libtorch/../../utils.h:37,
                 from /data/qtensor/tvm/src/relay/backend/contrib/libtorch/libtorch_codegen.cc:44:
/data/qtensor/tvm/include/tvm/runtime/device_api.h: In function ‘const char* tvm::runtime::DeviceName(int)’:
/data/qtensor/tvm/include/tvm/runtime/device_api.h:247:10: error: ‘kDLCUDA’ was not declared in this scope
  247 | case kDLCUDA:
      | ^ ~~~~~~
/data/qtensor/tvm/include/tvm/runtime/device_api.h:249:10: error: ‘kDLCUDAHost’ was not declared in this scope
  249 | case kDLCUDAHost:

```

---

<div class="post-metadata">

**Author:** ![leiwen83](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/leiwen83/32/3991_2.png) [@leiwen83](https://discuss.tvm.apache.org/u/leiwen83)\
**Post date:** [August 14, 2022, 2:43am UTC](https://discuss.tvm.apache.org/t/use-libtorch-build-fail-for-0-9/13319/2 "2022-08-14T02:43:27Z")

</div>

@t-vi any idea? seems to me that dlpack.h has the same DLPACK\_DLPACK\_H\_ for both pytorch’s and tvm’s 3rd package. So how to solve the conflict?

---

<div class="post-metadata">

**Author:** ![Hzfengsy](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/hzfengsy/32/2961_2.png) [@Hzfengsy](https://discuss.tvm.apache.org/u/Hzfengsy)\
**Post date:** [August 15, 2022, 7:10am UTC](https://discuss.tvm.apache.org/t/use-libtorch-build-fail-for-0-9/13319/3 "2022-08-15T07:10:25Z")

</div>

According to my personal experience, compiling with LibTorch is a bit tricky:

1. We need to install PyTorch (not only LibTorch) with cxx11 support. However, the PyTorch wheel from the official site does not contain cxx11.
2. Build TVM with LibTorch with cxx11 support. We can download it again or directly use the LibTorch embedded in the PyTorch folder.

I’m not sure why the PyTorch version matters. It’s just my observation.
