Using nvc++(-stdpar) with cmake results in linker error

I want to compile the following program for testing -stdpar in the NVIDIA HPC SDK.

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <execution>
#include <cmath>

int main()
    constexpr auto n = 1000000000;
    auto numbers = std::vector<float>(n);
    std::iota(numbers.begin(), numbers.end(), 0);
    std::transform(std::execution::par_unseq, numbers.begin(), numbers.end(), numbers.begin(),
                   [](auto a)
                   { return std::sqrt(a); });

The CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 3.20.0)
project(cpp_hpc LANGUAGES CXX CUDA)
find_package(CUDA 12.1 REQUIRED)
find_package(NVHPC REQUIRED PATHS "/opt/nvidia/hpc_sdk/Linux_x86_64/2023/cmake/")

add_executable(nvidia_hpc_test nvidia_hpc_test.cpp)

target_compile_options(nvidia_hpc_test PRIVATE -stdpar)
target_link_libraries(nvidia_hpc_test PRIVATE NVHPC::CUDA NVHPC::MATH)

Compilation results in linking error for all the cuda libraries.

Whereas compilation from directly invoking nvc++ from command line works without any extra linker arguments. All locations are added to the PATH and LD_LIBRARY_PATH environment variables.

Any help is highly appreciated.

“-stdpar” needs to be added to the link as well so the compiler knows to add the CUDA runtime libraries. “target_compile_options” only adds the flag to the compilation.

The likely fix is to add “target_link_options” which includes “-stdpar”.


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.