diff --git a/bench/Makefile.am b/bench/Makefile.am index 88575a5..39ce3c3 100644 --- a/bench/Makefile.am +++ b/bench/Makefile.am @@ -16,3 +16,7 @@ else test_main_LDADD += @LIBCTF_LD_LIBRARY_PATH@/libctf.a endif +if WITH_CUDA +test_main_CXXFLAGS = $(CUDA_CXXFLAGS) +test_main_LDADD += $(CUDA_LDFLAGS) +endif diff --git a/configure.ac b/configure.ac index cabeca4..cb25ce6 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,6 @@ AC_ARG_ENABLE([docs], [Enable building docs])], [build_docs=YES], [build_docs=NO]) - dnl LIBGC library options AC_ARG_WITH(libctf-prefix, AS_HELP_STRING([--with-libctf-prefix=path], @@ -50,6 +49,15 @@ AC_ARG_WITH(dgemm, [with_dgemm=NO], [with_dgemm=YES]) +AC_ARG_ENABLE([cuda], + [AS_HELP_STRING([--enable-cuda], + [Build with cuda])], + [WITH_CUDA=yes], + [WITH_CUDA=no]) +AC_ARG_VAR([NVCC], [Path to the nvidia cuda compiler.]) +AC_ARG_VAR([CUDA_LDFLAGS], [LDFLAGS to find libraries -lcuda and -lcudart.]) +AC_ARG_VAR([CUDA_CXXFLAGS], [CXXFLAGS to find the CUDA headers]) + dnl ----------------------------------------------------------------------- @@ -124,6 +132,21 @@ else [AC_MSG_ERROR([no ctf.hpp])]) fi +dnl CUDA NVIDIA ----------------------------------------------------------- + +AM_CONDITIONAL([WITH_CUDA], [test x${WITH_CUDA} = xyes]) +if test x${WITH_CUDA} = xyes; then + AC_MSG_RESULT([ + CUDA SUPPORT IS ENABLED + ----------------------- + ]) + AC_CHECK_PROGS([NVCC], [nvcc]) + AC_SUBST([CUDA_LDFLAGS]) + AC_DEFINE([HAVE_CUDA],1,[Wether we are using CUDA]) + # TODO: make sure to find cuda and cudart + # AC_SEARCH_LIBS([cudaMalloc], [cuda cudart], [FOUND_CUDA=yes]) +fi + dnl ----------------------------------------------------------------------- dnl Docs if test x${build_docs} = xYES; then diff --git a/cuda.nix b/cuda.nix new file mode 100644 index 0000000..cf5e454 --- /dev/null +++ b/cuda.nix @@ -0,0 +1,19 @@ +{pkgs}: +{ + + shellHook = '' + export NVCC=${pkgs.cudatoolkit}/bin/nvcc + + export CUDA_ROOT_PATH=${pkgs.cudatoolkit} + export CUDA_CXXFLAGS="-I${pkgs.openmpi.out}/include -I$CUDA_ROOT_PATH/include" + + # cudart + export CUDA_LIB_PATH=${pkgs.cudatoolkit.lib} + export CUDA_OUT_PATH=${pkgs.cudatoolkit.out} + + # in here is libcuda + export CUDA_X11LIB="${pkgs.linuxPackages.nvidia_x11}/lib" + export CUDA_LDFLAGS="-L$CUDA_X11LIB -L$CUDA_ROOT_PATH/lib -L$CUDA_LIB_PATH/lib -lcuda -lcudart" + ''; + +} diff --git a/shell.nix b/shell.nix index 4db21e5..5f4aa06 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,9 @@ -{ compiler ? "gcc", pkgs ? import {} , with-mkl ? false, docs ? true }: +{ compiler ? "gcc" +, pkgs ? import {} +, with-mkl ? false +, cuda ? false +, docs ? true +}: let @@ -8,10 +13,13 @@ let openblas = import ./etc/nix/openblas.nix { inherit pkgs; }; + cuda-pkg = if cuda then (import ./cuda.nix { inherit pkgs; }) else {}; + in pkgs.mkShell rec { + compiler-pkg = if compiler == "gcc11" then pkgs.gcc11 else if compiler == "gcc10" then pkgs.gcc10 @@ -50,7 +58,7 @@ pkgs.mkShell rec { = with pkgs; [ coreutils - git + git vim openmpi llvmPackages.openmp @@ -74,7 +82,7 @@ pkgs.mkShell rec { LD = "${compiler-pkg}/bin/ld"; shellHook - = #(if with-mkl then mkl.shellHook else openblas.shellHook) + = '' export OMPI_CXX=${CXX} export OMPI_CC=${CC} @@ -82,6 +90,7 @@ pkgs.mkShell rec { CC=${CC} LD=${LD} '' + + (if cuda then cuda-pkg.shellHook else "") ; } diff --git a/src/Makefile.am b/src/Makefile.am index 468c05a..cb46935 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,9 +1,23 @@ AUTOMAKE_OPTIONS = subdir-objects include $(top_srcdir)/atrip.mk -AM_CXXFLAGS = $(CTF_CPPFLAGS) +AM_CXXFLAGS = $(CTF_CPPFLAGS) -fmax-errors=1 lib_LIBRARIES = libatrip.a libatrip_a_CPPFLAGS = -I$(top_srcdir)/include/ -libatrip_a_SOURCES = ./atrip/Atrip.cxx +libatrip_a_SOURCES = ./atrip/Atrip.cxx \ + ./atrip/Blas.cxx \ + ./atrip/Complex.cxx + + +if WITH_CUDA +libatrip_a_CPPFLAGS += $(CUDA_CXXFLAGS) +libatrip_a_DEPENDENCIES = ./atrip/Equations.o +libatrip_a_LIBADD = ./atrip/Equations.o +./atrip/Equations.o: ./atrip/Equations.cxx + $(NVCC) -c -I../ $(CPPFLAGS) $(libatrip_a_CPPFLAGS) $< -o $@ +else +libatrip_a_SOURCES += ./atrip/Equations.cxx +endif + diff --git a/test/Makefile.am b/test/Makefile.am index 833b84c..66acfae 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -15,3 +15,8 @@ main_LDADD += $(CTF_BUILD_PATH)/lib/libctf.a else main_LDADD += @LIBCTF_LD_LIBRARY_PATH@/libctf.a endif + +if WITH_CUDA +main_CXXFLAGS = $(CUDA_CXXFLAGS) +main_LDADD += $(CUDA_LDFLAGS) +endif