viennacl / viennacl-dev

Developer repository for ViennaCL. Visit http://viennacl.sourceforge.net/ for the latest releases.
Other
281 stars 89 forks source link

Cannot compile against CUDA 9.1 on Ubuntu 18.04 #279

Closed TysonRayJones closed 5 years ago

TysonRayJones commented 5 years ago

Hi,

I'm trying to compile a simple example:

// demo.cpp

#include "viennacl/matrix.hpp"

int main(int argc, char* argv[]) {
    viennacl::matrix<double>  vcl_matrix(4, 5);
    vcl_matrix(0,2) = 1.0;
    return 0;
}

with command

nvcc -DVIENNACL_WITH_CUDA -IViennaCL demo.cpp

and file structure ViennaCL/viennacl/matrix.hpp (etc).

This causes a pretty huge error I've pasted into this pastebin, which begins with:

In file included from ViennaCL/viennacl/linalg/scalar_operations.hpp:40:0,
                 from ViennaCL/viennacl/scalar.hpp:30,
                 from ViennaCL/viennacl/tools/entry_proxy.hpp:27,
                 from ViennaCL/viennacl/detail/matrix_def.hpp:26,
                 from ViennaCL/viennacl/matrix.hpp:26,
                 from quest_viennacl.cpp:3:
ViennaCL/viennacl/linalg/cuda/scalar_operations.hpp: In function ‘typename viennacl::enable_if<((viennacl::is_scalar<T>::value && viennacl::is_scalar<ScalarT2>::value) && viennacl::is_any_scalar<FactorT>::value)>::type viennacl::linalg::cuda::as(ScalarT1&, const ScalarT2&, const NumericT&, viennacl::vcl_size_t, bool, bool)’:
ViennaCL/viennacl/linalg/cuda/scalar_operations.hpp:88:14: error: expected primary-expression before ‘<’ token
   as_kernel<<<1, 1>>>(viennacl::cuda_arg(s1),
              ^
ViennaCL/viennacl/linalg/cuda/scalar_operations.hpp:88:21: error: expected primary-expression before ‘>’ token
   as_kernel<<<1, 1>>>(viennacl::cuda_arg(s1),

I take it the CUDA syntax isn't being recognised. This seems specific to ViennaCL, since I CUDA compile other projects (e.g. QuEST) without issue on this system.

Is ViennaCL incompatible with CUDA 9.1? I'm compiling for a Quadro P6000 with computability 6.1, so need to use at least CUDA 8.0. Is there any way I can make this work?

TysonRayJones commented 5 years ago

(Note the same code compiles with CUDA 9.2 on MacOS 10.14 - perhaps this is a Ubuntu-specific issue)

karlrupp commented 5 years ago

You need to name your source file with extension .cu to make nvcc interpret the CUDA code correctly. Then, calling nvcc -DVIENNACL_WITH_CUDA -IViennaCL demo.cu should succeed.

karlrupp commented 5 years ago

An alternative is to pass -x cu to nvcc: https://stackoverflow.com/questions/26208784/cuda-cpp-files

TysonRayJones commented 5 years ago

Right you are - it's curious this wasn't needed on MacOS. Thanks very much for the prompt help (and for your work on a fantastic library)!