NVIDIA / AMGX

Distributed multigrid linear solver library on GPU
468 stars 136 forks source link

Error trying to build an app that uses AmgX #301

Closed gaaraujo closed 4 months ago

gaaraujo commented 4 months ago

Hi, I am trying to build an app that uses the AmgX library. I managed to compile AmgX successfully. However, I get errors when trying to compile an app that uses AmgX. The source code for this app is inside a folder src, with the main file being gifted.cu

To build this app, I use the following Makefile makefile.txt

That basically results in the following command being executed: /share/software/user/open/cuda/12.2.0/bin/nvcc src/gifted.cu -o gifted -Isrc -I"/share/software/user/open/cuda/12.2.0/include" -I"../amgx/include" -I"../amgx/thrust" -lcudart -L"/share/software/user/open/cuda/12.2.0/lib64" -lamgxsh -L"../amgx/build" -Xlinker "-rpath="./lib" " -ldl

Part of the output I get is the following:

/share/software/user/open/cuda/12.2.0/bin/nvcc src/gifted.cu -o gifted -Isrc -I"/share/software/user/open/cuda/12.2.0/include"  -I"../amgx/include" -I"../amgx/thrust" -lcudart -L"/share/software/user/open/cuda/12.2.0/lib64" -lamgxsh -L"../amgx/build" -Xlinker "-rpath="./lib" " -ldl 
../amgx/include/cusp/memory.h(28): error: identifier "amgx" is undefined
      using host_memory = amgx::thrust::host_system_tag;
                          ^

../amgx/include/cusp/memory.h(28): error: expected a ";"
      using host_memory = amgx::thrust::host_system_tag;
                              ^

../amgx/include/cusp/memory.h(29): error: identifier "amgx" is undefined
      using device_memory = amgx::thrust::device_system_tag;
                            ^

../amgx/include/cusp/memory.h(29): error: expected a ";"
      using device_memory = amgx::thrust::device_system_tag;
                                ^

../amgx/include/cusp/memory.h(30): error: identifier "amgx" is undefined
      using any_memory = amgx::thrust::any_system_tag;
                         ^

../amgx/include/cusp/memory.h(30): error: expected a ";"
      using any_memory = amgx::thrust::any_system_tag;
                             ^

../amgx/include/vector_thrust_allocator.h(58): error: qualified name is not allowed
          typedef amgx::thrust::device_ptr<T> pointer;
                  ^

../amgx/include/vector_thrust_allocator.h(58): error: explicit type is missing ("int" assumed)
          typedef amgx::thrust::device_ptr<T> pointer;

Any idea of what I could be missing in my makefile?

marsaev commented 4 months ago

You should not include AMGX sources directly. When you build AMGX use make install and use provided install files (library and headers) for your application (https://github.com/NVIDIA/AMGX/blob/main/CMakeLists.txt#L286-L289)

gaaraujo commented 4 months ago

Hi, @marsaev! Thanks for your quick answer! Just to clarify:

I built AmgX using the following according to README.md

mkdir build
cd build
cmake ../
make -j16 all

Instead, should I do this?

mkdir build
cd build
cmake ../
make -j16 install
gaaraujo commented 4 months ago

Update:

I ran make install inside the build directory of amgx, and obtained a new lib folder containing libamgxsh.so.

My makefile now runs the following:

/share/software/user/open/cuda/12.2.0/bin/nvcc src/gifted.cu -o gifted -Isrc -I"/share/software/user/open/cuda/12.2.0/include" -I"../amgx/include" -lcudart -L"/share/software/user/open/cuda/12.2.0/lib64" -lamgxsh -L"../amgx/lib" -Xlinker "-rpath="./lib" " -ldl

Unfortunately, I still get the same error. What else could I be missing?

marsaev commented 4 months ago

Command line looks right. Just to clarify - your files, i.e. gifted.cu should include only amgx_c.h header. According to error it seems other AMGX might be included there. Can you check what you include in sources?

gaaraujo commented 4 months ago

Thanks again for replying!

Indeed, I had some references to other libraries. In one of the files, I had:

#include <cusp/csr_matrix.h>
#include <cusp/print.h>

Getting rid of these headers worked! Thanks!

gaaraujo commented 4 months ago

Closing the issue!