rusty1s/pytorch_cluster

C++ API Exception (CPP/c10::Error) when using nearest_cuda

MaxMayya opened this issue · 10 comments

Hi,
I'm trying to use the C++ API of pytorch_cluster in conjunction with the LibTorch C++ API. I managed to build and install the former WITH_CUDA=ON and tried to reproduce the nearest example below:

#include <torch/torch.h>
#include <torchcluster/cluster.h>

int main() {
    std::cout << torch::cuda::is_available() << std::endl;
    torch::Device device(torch::kCUDA);
    auto options = torch::TensorOptions()
        .dtype(torch::kFloat16)
        .layout(torch::kStrided)
        .device(device)
        .requires_grad(false);
    auto x = torch::tensor({{-1, -1}, {-1, 1}, {1, -1}, {1, 1}}, options);
    auto batch_x = torch::tensor({0, 0, 0, 0}, options);
    auto y = torch::tensor({{-1, 0}, {1, 0}}, options);
    auto batch_y = torch::tensor({0, 0}, options);
    auto cluster = nearest(x, y, batch_x, batch_y);
    std::cout << cluster << std::endl;
    return 0;
}

Reaching the nearest function (which calls nearest_cuda), I get the following exception error:

Exception has occurred: CPP/c10::Error
Unhandled exception at 0x00007FFC29FBCD29 in TorchExample.exe: Microsoft C++ exception: c10::Error at memory location 0x000000125A1DEDC0.

Precisely, the error occurs when invoking AT_DISPATCH_FLOATING_TYPES_AND.

Environment:

  • OS: Windows 10 Pro
  • Torch C++ installation: libtorch-win-shared-with-deps-1.13.1+cu117
  • Compiler: Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30147 for x64
  • Build variant: RelWithDebInfo
  • Torch Cluster built from master

I'm sure that the torch_cluster build links correctly to the LibTorch. I've already, successfully, used LibTorch alone with CUDA, but cannot tell weather this is fully related to torch_cluster.

Any thoughts?

Thank you in advance

Mh, I sadly don't have a good advice for you since I am not actively using the C++ bindings. I can only link you to the PyG C++ example, which works fine for me. Might be a good idea to confirm that the same holds true for you.

Thanks for the pointer. The only difference I can tell is that they suggest that torch is installed via conda. However, there is no way to install torch C++ bindings via conda (at least this is what Pytorch tells to do). The question is: if I use conda over the LibTorch C++, would I lose the ability to use the C++ APIs?

I am not sure TBH. So far, I just installed PyTorch via conda, and then link to libtorch provided in the Python package in site-packages.

Okay then, I'll try that option and update here. Thanks

Okay then, I'll try that option and update here. Thanks

I have the same problem, have you solved it?

Not yet! I've just tried the conda package path but in vain. I still have the same issue. I however was obliged to copy-paste the torchcluster.dll from the install directory to the target application directory. Don't know if this breaks any implicite mechanisms but I'm already successfully doing so for the torch library (based on the torch example).

@alpha-beta-user what is your OS?

@alpha-beta-user what is your OS?

Windows 11

I opened a discussion here, please consider adding additional inputs if you have any to help resolve this issue ASAP.

This issue had no activity for 6 months. It will be closed in 2 weeks unless there is some new activity. Is this issue already resolved?