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

Build error on cpp/custom-dataset #1255

Open
dribllerrad opened this issue May 9, 2024 · 1 comment · May be fixed by #1293
Open

Build error on cpp/custom-dataset #1255

dribllerrad opened this issue May 9, 2024 · 1 comment · May be fixed by #1293

Comments

@dribllerrad
Copy link

I'm getting a build error on a data type conversion with this example:
https://github.com/pytorch/examples/tree/main/cpp/custom-dataset

Error message:

error: conversion from 'const long' to 'detail::TensorDataContainer' is ambiguous
[build]     auto tlabel = torch::tensor(data[index].second, torch::kLong);
[build]                                 ^~~~~~~~~~~~~~~~~~

I believe the paths to libtorch and opencv are good because other sample apps using them compile fine.

I've tried playing around with some casts (both with c++ casts and torch method conversions like .to(torch::kFloat) ) but I don't really know the library enough to troubleshoot. Removing the const-ness of the data also didn't help (revert of b2832cc).

torch env

PyTorch version: 2.3.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 14.4.1 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.3.9.4)
CMake version: version 3.29.3
Libc version: N/A

Python version: 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] (64-bit runtime)
Python platform: macOS-14.4.1-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Apple M1 Max

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] torch==2.3.0
[pip3] torchaudio==2.3.0
[pip3] torchvision==0.18.0
[conda] Could not collect
@nccrrv
Copy link

nccrrv commented Oct 16, 2024

I encountered the same issue.
After checking, I found that there is no long type in ScalarType.h.

#define AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_AND_QINTS(_) \
  _(uint8_t, Byte) /* 0 */                               \
  _(int8_t, Char) /* 1 */                                \
  _(int16_t, Short) /* 2 */                              \
  _(int, Int) /* 3 */                                    \
  _(int64_t, Long) /* 4 */                               \
  _(at::Half, Half) /* 5 */                              \
  _(float, Float) /* 6 */                                \
  _(double, Double) /* 7 */                              \
  ...

The closest type is int64_t.
So, this seems to be an issue caused by platform differences.
On Linux, std::is_same_v<int64_t, long> == true,
while on my VS and your platform, std::is_same_v<int64_t, long> == false.

We can fix this by changing long to int64_t in the example.
(Translated by AI)

我遇到了同样的问题
经过检查发现,在ScalarType.h里并没有long类型
与之最近的是int64_t
所以这应该是一个平台差异所导致的问题
在linux上std::is_same_v<int64_t,long>==true
而在我的VS和你的平台上std::is_same_v<int64_t,long>==false

可以把例子里的long改为int64_t来修复

@nccrrv nccrrv linked a pull request Oct 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants