ddemidov / vexcl

VexCL is a C++ vector expression template library for OpenCL/CUDA/OpenMP
http://vexcl.readthedocs.org
MIT License
699 stars 81 forks source link

Issue backend CUDA with boost 1.69.0 and cuda 10 #269

Closed MaximeRoux closed 5 years ago

MaximeRoux commented 5 years ago

Hello, I want to use the cuda backend of vexcl but it doesn't work I have the following error :

Error explicit specialization of class "vex::traits::is_vector_expr_terminal<size_t, void>" must precede its first use C:\Utils\vexcl-master\vexcl\backend\cuda\texture_object.hpp 41

I have boost 1.69, visual studio 2017 15.9.7 and cuda 10. Maybe my boost version is too recent ?

ddemidov commented 5 years ago

Can you provide a minimal example that shows this issue when compiled?

MaximeRoux commented 5 years ago

This one for example :

#include <stdio.h>
#include <stdexcept>
#include <iostream>

#define VEXCL_BACKEND_CUDA

#include <vexcl/vexcl.hpp>

int main(void)
{

    vex::Context ctx(vex::Filter::GPU);

    if (!ctx) throw std::runtime_error("No devices available.");

    // Print out list of selected devices:
    std::cout << ctx << std::endl;

    return 0;

}
ddemidov commented 5 years ago

I am sorry, I don't have Windows or Visual Studio, and I can not reproduce the issue with boost 1.69 and cuda 10.0.130 on my linux machine. Using either this CMakeLists.txt:

cmake_minimum_required(VERSION 3.11)
project(hello)

find_package(VexCL)
add_executable(hello hello.cpp)
target_link_libraries(hello VexCL::CUDA)

or this command line:

g++ -o hello hello.cpp -I ~/work/vexcl -I /opt/cuda/include/ -lcuda

yields no compilation errors here.

MaximeRoux commented 5 years ago

I compile with nvcc because the compiler (msvc) doesn't recognize any CUDA functions or macro.

ddemidov commented 5 years ago

VexCL CUDA backend uses driver API (as opposed to runtime API supported by nvcc), so you don't need to compile the code with nvcc. Can you try to compile it with cl.exe instead?

MaximeRoux commented 5 years ago

You mind compiling it using the OpenCL backend instead of the CUDA backend ?

ddemidov commented 5 years ago

It works with OpenCL as well as with CUDA backend for me, replacing VEXCL_BACKEND_CUDA with VEXCL_BACKEND_OPENCL in your example, and using

g++ -o hello hello.cpp -I ~/work/vexcl -lOpenCL 
MaximeRoux commented 5 years ago

For me It works for VEXCL_BACKEND_COMPUTE and VEXCL_BACKEND_COMPUTE but not for VEXCL_BACKEND_CUDA

MaximeRoux commented 5 years ago

Excuse me for my last comment I wanted to say : You mean compiling it using the OpenCL backend instead of the CUDA backend when you said "Can you try to compile it with cl.exe instead? "

ddemidov commented 5 years ago

No, I meant that you should treat the project as normal (non-cuda) C++ project. No need to involve nvcc at all. nvcc is only used at run-time to compile the generated kernels. Your program is compiled with host compiler (cl.exe in case of the visual studio, or g++/clang++ on linux) and is linked against cuda.lib/libcuda.so.

MaximeRoux commented 5 years ago

I treat the project as normal now (as a C++ project), I had already linked cuda.lib but I still have the same issue than before, msvc doesn't recognize any CUDA functions or macro (like CUDA_SUCCESS for example).

ddemidov commented 5 years ago

Is it possible MSVC does not know how to include <cuda.h> and you just need to set the correct include path for the project? A simple test would be a successful compilation of

#include <iostream>
#include <cuda.h>

int main() {
    std::cout << CUDA_SUCCESS << std::endl;
}
MaximeRoux commented 5 years ago

I resolved the problem my compiler took the cuda.h of boost... But now I have the same error than before with nvcc which is : 1>C:\Utils\vexcl-master\vexcl/backend/cuda/texture_object.hpp(41): error : explicit specialization of class "vex::traits::is_vector_expr_terminal<size_t, void>" must precede its first use ( line 20 of C:\Utils\boost_1_69_0\boost\mpl\aux_\has_type.h )

ddemidov commented 5 years ago

The error is different now (it references C:\Utils\boost_1_69_0\boost\mpl\aux_\has_type.h instead of C:\Utils\vexcl-master\vexcl\backend\cuda\texture_object.hpp) and I am still not able to reproduce this. I think there is probably another issue with your project configuration.

Are you able to configure and compile vexcl examples/tests with cmake (cmake will generate a visual studio solution for you)? And after that, try to use the cmake I pasted above with your own example.

MaximeRoux commented 5 years ago

But to use your makefile I need the file FindVexcl.cmake

ddemidov commented 5 years ago

It will be available once you configure vexcl (it registers itself in cmake local packages).

MaximeRoux commented 5 years ago

What did you mean by "configure vexcl "?

ddemidov commented 5 years ago

Something like this:

cd C:\Utils\vexcl-master\
mkdir build
cd build
cmake ..

or an equivalent with cmake GUI.

MaximeRoux commented 5 years ago

I did that with cmake GUI, the configuaration and generation worked but still no FindVexcl.cmake.

ddemidov commented 5 years ago

I don't think I tried this on Windows. Another option would be to add vexcl as a subfolder to your project and replace find_package (VexCL) with add_subdirectory(vexcl) in your CMakeLists.txt.

MaximeRoux commented 5 years ago

Thanks, finally it found the package. But even with the cmake I still have the same problem with is_vector_expr_terminal

ddemidov commented 5 years ago

Sorry, I have no other ideas besides may be try newer version of visual studio.

MaximeRoux commented 5 years ago

No problem, thanks for your help

MaximeRoux commented 5 years ago

I tried to compile the examples of vexcl as you said before but I have many errors like this one CMake Error at CMakeLists.txt:10 (add_executable): Target "complex_spmv" links to target "VexCL::Backend" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? Call Stack (most recent call first): CMakeLists.txt:27 (add_vexcl_examples)

ddemidov commented 5 years ago

What value of VEXCL_BACKEND cmake variable you used? The error looks like vexcl cmake was not able to find the selected backend. It is possible you need to help cmake by providing paths to include/library folders. If you show all settings in cmake gui, (check advanced):

cmake-gui

you should be able to see if there are any OpenCL/CUDA-related settings with undefined values.

MaximeRoux commented 5 years ago

cmake_gui_vexcl

I compile this way

ddemidov commented 5 years ago

"Where is the source code" field should point to the vexcl root (vexcl-master).

MaximeRoux commented 5 years ago

Yes this one works cmake_gui_vexcl_master

ddemidov commented 5 years ago

You also need to check "VEXCL_BUILD_EXAMPLES" and/or "VEXCL_BUILD_TESTS" to actually try compiling anything. And set "VEXCL_BACKEND" to "CUDA".

MaximeRoux commented 5 years ago

Yes thanks I found these options, the configuration is working well but not the generation I have the following error : cmake_gui_vexcl_example_cuda_backend

MaximeRoux commented 5 years ago

I removed the part Thrust interoperation examples of the cmake so now it is well generated and we can see at compilation that I have the same error as before : Compilation_vexcl_example_backend_cuda

ddemidov commented 5 years ago

These errors are different from what you got initially and actually make some sense now. These say that template specializations for cl_ulong and _int64_t have been declared twice. I suspect the reason is that CUtexObject on Windows is actually typedef'ed as _uint64_t and the errors come from these specializations:

https://github.com/ddemidov/vexcl/blob/192137a2c1f74de97dc2859d8af76b822a9a4dd6/vexcl/backend/cuda/texture_object.hpp#L40-L46

Can you try to comment out these lines and see if your examples compile? It should be safe to comment out lines 40-42.

Unfortunately, if CUtexObject is indeed just _uint64_ton windows, then there is no way to use texture objects after commenting lines 44-46.

MaximeRoux commented 5 years ago

When I comment the lines 40 to 46 I have the following errors : Compilation_vexcl_example_backend_cuda_comment_texture_object

ddemidov commented 5 years ago

These look like cmake errors, not compiler ones.

MaximeRoux commented 5 years ago

Yes but I didn't change the cmake, maybe I have to remove texture_object.hpp

ddemidov commented 5 years ago

I would just try to reconfigure cmake first (that is, remove everything from the build directory and run the cmake-gui again).

MaximeRoux commented 5 years ago

Finally it works I had a problem with the file cmake.exe, thanks for your help

ddemidov commented 5 years ago

Thank you for rising this! Do you mind if we try to solve the issue with CUtexObject before we close this? I think I know how to solve this, but I would need your help testing if the solution actually works.

ddemidov commented 5 years ago

Could you please see if #270 works for you and that tests/image.exe works with the CUDA backend?

MaximeRoux commented 5 years ago

So, I have to modify texture_object.hpp ?

ddemidov commented 5 years ago

You can just download the updated code from #270 at https://github.com/ddemidov/vexcl/archive/issue-269.zip.

MaximeRoux commented 5 years ago

Compilation for image works well but not the runtime I have this :

seed: 1553172225
1. GeForce GTX 1050 Ti
2. GeForce GTX 1050 Ti

Running 2 test cases...
nvcc fatal   : Cannot find compiler 'cl.exe' in PATH
typedef unsigned char       uchar;
typedef unsigned int        uint;
typedef unsigned short      ushort;
typedef unsigned long long  ulong;

extern "C" __global__ void vexcl_vector_kernel
(
  ulong n,
  float * prm_1,
  int prm_2
)
{
  for
  (
    ulong idx = blockDim.x * blockIdx.x + threadIdx.x, grid_size = blockDim.x * gridDim.x;
    idx < n;
    idx += grid_size
  )
  {
    prm_1[idx] = prm_2;
  }
}
unknown location(0): fatal error: in "cr/image1d": class std::runtime_error: nvcc invocation failed
C:\Utils\vexcl-issue-269\tests\image.cpp(10): last checkpoint: "image1d" test entry

*** 1 failure is detected in the test module "Image"

C:\Utils\vexcl-master\build\build\tests\Debug\image.exe (process 21912) exited with code 201.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
ddemidov commented 5 years ago

The runtime can not find cl.exe which is the visual studio compiler. I think you need to either add the location of cl.exe to PATH environment variable, or (easier) run the tests from the visual studio command prompt (it used to be in the Start menu under Visual studio/tools).

MaximeRoux commented 5 years ago

Yes it seems to be working

seed: 1553175864
1. GeForce GTX 1050 Ti
2. GeForce GTX 1050 Ti

Running 2 test cases...
kernel.cu
kernel.cu
kernel.cu

*** No errors detected
ddemidov commented 5 years ago

Thanks again for testing!