[CMake] Possible bug/incompatibility FindCUDA with Visual Studio 2017

Andrea Borsic aborsic at gmail.com
Thu Aug 10 05:49:32 EDT 2017


Hi All,

I am working on this platform:

  * Windows 10 64bit
  * Visual Studio 2015 Community Edition
  * Visual Studio 2017 Community Edition
  * CUDA 8.0
  * CMake 3.9

I am in the middle of switching from VS2015 to VS2017, but CUDA projects 
fail to properly compile under VS2017 as the compiler/linker fail to 
find tools on the path setup by CMake. I believe this is 
bug/incompatibly of the CMake FindCUDA module with VS2017.

To reproduce the problem I am attaching a tiny project

  * main.cu is a minimal CUDA example from the web
  * CMakeLists.txt is a CMake file that leads to a successful build
    under VS2015 and unsuccessful under VS2017
  * Output VS2015 is the output from building the project under VS2015
    (all targets built OK)
  * Output VS2017 is the output from building the project under VS2015
    (1 target OK one target fails)

I have noticed also that oddly under VS2017 an "x64" and "main.dir" 
directories are created outside the build dir, and at the level of the 
source directory.

I thought of reporting this to the list, and any help is welcome,

Thank you and Best Regards,

Andrea

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170810/827a42cd/attachment-0001.html>
-------------- next part --------------
PROJECT (Test)

CMAKE_MINIMUM_REQUIRED(VERSION 3.1)

FIND_PACKAGE(CUDA REQUIRED)

SET(CUDA_NVCC_FLAGS "-arch=sm_35" CACHE STRING "nvcc flags" FORCE)

CUDA_ADD_EXECUTABLE(main main.cu)


-------------- next part --------------
#include <stdio.h>

//
// Nearly minimal CUDA example.
// Compile with:
//
// nvcc -o example example.cu
//

#define N 1000

//
// A function marked __global__
// runs on the GPU but can be called from
// the CPU.
//
// This function multiplies the elements of an array
// of ints by 2.
//
// The entire computation can be thought of as running
// with one thread per array element with blockIdx.x
// identifying the thread.
//
// The comparison i<N is because often it isn't convenient
// to have an exact 1-1 correspondence between threads
// and array elements. Not strictly necessary here.
//
// Note how we're mixing GPU and CPU code in the same source
// file. An alternative way to use CUDA is to keep
// C/C++ code separate from CUDA code and dynamically
// compile and load the CUDA code at runtime, a little
// like how you compile and load OpenGL shaders from
// C/C++ code.
//
__global__
void add(int *a, int *b) {
    int i = blockIdx.x;
    if (i<N) {
        b[i] = 2*a[i];
    }
}

int main() {
    //
    // Create int arrays on the CPU.
    // ('h' stands for "host".)
    //
    int ha[N], hb[N];

    //
    // Create corresponding int arrays on the GPU.
    // ('d' stands for "device".)
    //
    int *da, *db;
    cudaMalloc((void **)&da, N*sizeof(int));
    cudaMalloc((void **)&db, N*sizeof(int));

    //
    // Initialise the input data on the CPU.
    //
    for (int i = 0; i<N; ++i) {
        ha[i] = i;
    }

    //
    // Copy input data to array on GPU.
    //
    cudaMemcpy(da, ha, N*sizeof(int), cudaMemcpyHostToDevice);

    //
    // Launch GPU code with N threads, one per
    // array element.
    //
    add<<<N, 1>>>(da, db);

    //
    // Copy output array from GPU back to CPU.
    //
    cudaMemcpy(hb, db, N*sizeof(int), cudaMemcpyDeviceToHost);

    for (int i = 0; i<N; ++i) {
        printf("%d\n", hb[i]);
    }

    //
    // Free up the arrays on the GPU.
    //
    cudaFree(da);
    cudaFree(db);

    return 0;
}
-------------- next part --------------
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
1>  Checking Build System
1>  CMake does not need to re-run because D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/build_win64_vs2015_cuda8/CMakeFiles/generate.stamp is up-to-date.
2>------ Build started: Project: main, Configuration: Debug x64 ------
2>  Building NVCC (Device) object CMakeFiles/main.dir/Debug/main_generated_main.cu.obj
2>  main.cu
2>  main.cu
2>  Building Custom Rule D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/src/CMakeLists.txt
2>  CMake is re-running because D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/build_win64_vs2015_cuda8/CMakeFiles/generate.stamp is out-of-date.
2>    the file 'D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/build_win64_vs2015_cuda8/CMakeFiles/main.dir/main_generated_main.cu.obj.depend'
2>    is newer than 'D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/build_win64_vs2015_cuda8/CMakeFiles/generate.stamp.depend'
2>    result='-1'
2>  -- Configuring done
2>  -- Generating done
2>  -- Build files have been written to: D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/build_win64_vs2015_cuda8
2>     Creating library D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/build_win64_vs2015_cuda8/Debug/main.lib and object D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/build_win64_vs2015_cuda8/Debug/main.exp
2>  main.vcxproj -> D:\Dropbox\NES_Projects_Technical\Active\HP-EIT\Test Cmake VS2017\build_win64_vs2015_cuda8\Debug\main.exe
2>  main.vcxproj -> D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/build_win64_vs2015_cuda8/Debug/main.pdb (Full PDB)
3>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug x64 ------
3>Project not selected to build for this solution configuration 
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 1 skipped ==========
-------------- next part --------------
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
1>Checking Build System
1>CMake does not need to re-run because D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake VS2017/build_win64_vs2017_cuda8/CMakeFiles/generate.stamp is up-to-date.
2>------ Build started: Project: main, Configuration: Debug x64 ------
2>Building NVCC (Device) object CMakeFiles/main.dir/Debug/main_generated_main.cu.obj
2>Failed to run C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/bin (The system cannot find the file specified.
2>
2>).
2>CMake Error at main_generated_main.cu.obj.Debug.cmake:222 (message):
2>  Error generating D:/Dropbox/NES_Projects_Technical/Active/HP-EIT/Test Cmake
2>  VS2017/build_win64_vs2017_cuda8/CMakeFiles/main.dir//Debug/main_generated_main.cu.obj
2>
2>
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1.
2>Done building project "main.vcxproj" -- FAILED.
3>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug x64 ------
3>Project not selected to build for this solution configuration 
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 1 skipped ==========


More information about the CMake mailing list