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

[BUG]: __assert_fail redefinition conflict with LibTorch #2571

Closed
1 task done
osayamenja opened this issue Oct 13, 2024 · 4 comments · Fixed by #2577
Closed
1 task done

[BUG]: __assert_fail redefinition conflict with LibTorch #2571

osayamenja opened this issue Oct 13, 2024 · 4 comments · Fixed by #2577
Labels
bug Something isn't working right.

Comments

@osayamenja
Copy link

osayamenja commented Oct 13, 2024

Is this a duplicate?

Type of Bug

Compile-time Error

Component

libcu++

Describe the bug

We redefine __assert_fail() here but this causes a linkage conflict/error when built with LibTorch that also defines the assertion.

See error below:

error: linkage specification is incompatible with previous "__assert_fail" (declared at line 72 of .../libcudacxx/include/cuda/std/__cccl/assert.h)

My current workaround is to add a header guard condition eliding the definition in torch. I decided to mention this here, since this issue would probably get missed among the many other open issues at PyTorch GitHub.

How to Reproduce

Make a cpp project linking both LibTorch and CCCL, this can be done easily with CMake.

Suggested CMakeLists.txt

# >= 3.24 for 'native' architecture
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
project(example-app CUDA CXX)

# Set some standard props
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
set(CMAKE_CUDA_ARCHITECTURES "native")
set(CMAKE_CUDA_STANDARD 20)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
 
find_package(CUDAToolkit REQUIRED)

# install from https://download.pytorch.org/libtorch/cu124/libtorch-shared-with-deps-2.4.1%2Bcu124.zip
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

add_executable(example-app example-app.cu)

set_target_properties(example-app PROPERTIES
	POSITION_INDEPENDENT_CODE ON
        CUDA_SEPARABLE_COMPILATION ON
)

target_link_libraries(example-app PRIVATE "${TORCH_LIBRARIES}")

# Assuming CPM.cmake is available
include(cmake/CPM.cmake)
CPMAddPackage(
        NAME CCCL
        GITHUB_REPOSITORY nvidia/cccl
        GIT_TAG main # Fetches the latest commit on the main branch
)
if(CCCL_ADDED)
    target_link_libraries(example-app PRIVATE CCCL::CCCL)
endif()

example-app.cu

#include <torch/torch.h>
#include <cuda/std/array>

int main() {
  cuda::std::array<float, 4> a{{0,1,2,3}};
  const auto t = torch::from_blob(a.data(), {2,2});
  std::cout << t << std::endl;
}

Expected behavior

Code should compile, but this might be a tricky to resolve with torch.

Reproduction link

No response

Operating System

Ubuntu Linux 22.04

nvidia-smi output

Sat Oct 12 20:58:52 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.35.03              Driver Version: 560.35.03      CUDA Version: 12.6     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA A100 80GB PCIe          Off |   00000000:01:00.0 Off |                    0 |
| N/A   36C    P0             52W /  300W |       1MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   1  NVIDIA A100 80GB PCIe          Off |   00000000:25:00.0 Off |                    0 |
| N/A   37C    P0             56W /  300W |       1MiB /  81920MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

NVCC version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Wed_Aug_14_10:10:22_PDT_2024
Cuda compilation tools, release 12.6, V12.6.68
Build cuda_12.6.r12.6/compiler.34714021_0

@osayamenja osayamenja added the bug Something isn't working right. label Oct 13, 2024
@github-project-automation github-project-automation bot moved this to Todo in CCCL Oct 13, 2024
@osayamenja osayamenja changed the title [BUG]: __assert_fail redefinition conflict [BUG]: __assert_fail redefinition conflict with LibTorch Oct 13, 2024
@fbusato
Copy link
Contributor

fbusato commented Oct 14, 2024

technically, the issue is more on the LibTorch side. We could potentially handle __SYCL_DEVICE_ONLY__ to avoid conflicts even if it is not intended to be supported by CUDA, see https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html. @miscco

@miscco
Copy link
Collaborator

miscco commented Oct 14, 2024

Actually, I believe the issue is the missing host device attribute

@miscco
Copy link
Collaborator

miscco commented Oct 14, 2024

@osayamenja could you check whether just adding _CCCL_HOST_DEVICE instead of extern would fix the redeclaration issue?

@osayamenja
Copy link
Author

@miscco fix works! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants