Clang error: cannot find libdevice for A; provide path to different CUDA installation via '--cuda-path', or pass '-nocudalib' to build without linking with libdevice (err_drv_no_cuda_libdevice)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: cannot find libdevice for A; provide path to different CUDA installation via '--cuda-path', or pass '-nocudalib' to build without linking with libdevice (since 14.0)
error: cannot find libdevice for A. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice. (until 13.0)
Type Error
Category None
Internal Id err_drv_no_cuda_libdevice
Internal Message cannot find libdevice for %0; provide path to different CUDA installation via '--cuda-path', or pass '-nocudalib' to build without linking with libdevice (since 14.0)
cannot find libdevice for %0. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice. (until 13.0)
Regular Expression (?:error|fatal error)\: cannot find libdevice for (.*?); provide path to different CUDA installation via '\-\-cuda\-path', or pass '\-nocudalib' to build without linking with libdevice
First Commit 2016-08-03 02a1e973a80a [CUDA] Fix libdevice selection.

Description

The error is issued by the Clang compiler when it is unable to locate the libdevice library necessary for CUDA compilation. This situation can arise during the compilation of CUDA code, where libdevice provides a collection of standard functions and is crucial for the NVVM compilation path. The error message suggests two potential resolutions: providing the path to a different CUDA installation with the --cuda-path option if the current path is incorrect or outdated, or opting to compile without linking against libdevice by passing the -nocudalib flag. This flexibility allows the user to proceed with compilation either by ensuring the correct CUDA resources are available or by opting out of their usage, which might be suitable in scenarios where libdevice functionalities are not required.  
AI Generated

Example

In the following example, an attempt is made to compile CUDA code using the Clang compiler. The source code consists of a device function f() marked with __device__, which signifies that f() runs on the GPU. The main function tries to call f(), which is an operation typically not allowed as __device__ functions can only be called from other device or global functions, not from host code. This code snippet triggers multiple error messages from the Clang compiler. The first error indicates that the compiler cannot specify an output file when generating multiple outputs, a common issue when the compilation setup is incorrect.

The subsequent messages are closely related to CUDA compilation issues. The compiler reports that it cannot find the CUDA installation, suggesting the user provide the path to the CUDA installation via the --cuda-path option, or pass the -nocudainc flag to build without including the CUDA headers. Furthermore, the error of interest concerning the inability to find libdevice for the specified GPU architecture ('sm_35') is displayed. It repeats the guidance to provide a different CUDA installation path with --cuda-path or to compile without linking with libdevice by passing -nocudalib. Finally, the error about the missing CUDA installation is reiterated, reinforcing the need to specify the CUDA path or opt out from using CUDA includes, highlighting challenges that may occur during CUDA code compilation when the environment is not correctly configured.

 
AI Generated


Flags -xcuda

[Try out in Compiler Explorer]

Source
__device__ void f() { }

int main() { f(); }
// __device__ function called from host code
Compiler Output
clang++: error: cannot specify -o when generating multiple output files
clang++: error: cannot find CUDA installation; provide its path via '--cuda-path', or pass '-nocudainc' to build without CUDA includes
clang++: error: cannot find libdevice for sm_35; provide path to different CUDA installation via '--cuda-path', or pass '-nocudalib' to build without linking with libdevice
clang++: error: cannot find CUDA installation; provide its path via '--cuda-path', or pass '-nocudainc' to build without CUDA includes


Clang Internals (17.0.6)

Git Commit Message

[CUDA] Fix libdevice selection.

This makes clang's libdevice selection match that of NVCC as described in
http://docs.nvidia.com/cuda/libdevice-users-guide/basic-usage.html#version-selection

If required libdevice variant is not found, driver now fails with an error.

Differential Revision: https://reviews.llvm.org/D23037

llvm-svn: 277542

Used in Clang Sources

This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.

clang/lib/Driver/ToolChains/Cuda.cpp (line 825)

void CudaToolChain::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadingKind) const {
  // ...
  if (LibDeviceFile.empty()) {
    getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;