conda-forge / nvcc-feedstock

A conda-smithy repository for nvcc.
BSD 3-Clause "New" or "Revised" License
12 stars 23 forks source link

Add -ICONDA_PREFIX/include to nvcc #33

Closed pearu closed 5 years ago

pearu commented 5 years ago

Checklist

This PR adds -I$CONDA_PREFIX/include to nvcc options to ease finding the library headers installed by conda.

conda-forge-linter commented 5 years ago

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

pearu commented 5 years ago

@conda-forge-admin, please rerender

conda-forge-linter commented 5 years ago

Hi! This is the friendly automated conda-forge-webservice.

I tried to re-render for you, but it looks like I wasn't able to push to the pearu/nvcc-include branch of Quansight/nvcc-feedstock. Did you check the "Allow edits from maintainers" box?

isuruf commented 5 years ago

The build system of a package should use CFLAGS, CPPFLAGS, CXXFLAGS, LDFLAGS. Adding this here would only just mask the issue that these env variable are not used. -1 on this PR.

pearu commented 5 years ago

Apparently, nvcc does not use CFLAGS, CPPFLAGS, CXXFLAGS, LDFLAGS. For instance, running nvcc -v test.cu (that has #include "boost/regexp.hpp") in test conda environment with boost-cpp installed, the output is:

#$ _SPACE_= 
#$ _CUDART_=cudart
#$ _HERE_=/usr/local/cuda-10.1.243/bin
#$ _THERE_=/usr/local/cuda-10.1.243/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_DIR_=targets/x86_64-linux
#$ TOP=/usr/local/cuda-10.1.243/bin/..
#$ NVVMIR_LIBRARY_DIR=/usr/local/cuda-10.1.243/bin/../nvvm/libdevice
#$ LD_LIBRARY_PATH=/usr/local/cuda-10.1.243/bin/../lib:/usr/local/cuda-10.1.243/lib64:
#$ PATH=/usr/local/cuda-10.1.243/bin/../nvvm/bin:/usr/local/cuda-10.1.243/bin:/home/pearu/miniconda3/conda-bld/nvcc_1574067209285/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_p:/home/pearu/miniconda3/conda-bld/nvcc_1574067209285/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_p/bin:/home/pearu/miniconda3/conda-bld/nvcc_1574067209285/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_p/bin:/usr/local/cuda-10.1.243/bin:/home/pearu/miniconda3/bin:/home/pearu/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
#$ INCLUDES="-I/usr/local/cuda-10.1.243/bin/../targets/x86_64-linux/include"  
#$ LIBRARIES=  "-L/usr/local/cuda-10.1.243/bin/../targets/x86_64-linux/lib/stubs" "-L/usr/local/cuda-10.1.243/bin/../targets/x86_64-linux/lib"
#$ CUDAFE_FLAGS=
#$ PTXAS_FLAGS=
#$ "/home/pearu/miniconda3/conda-bld/nvcc_1574067209285/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_p/bin"/x86_64-conda_cos6-linux-gnu-c++ -D__CUDA_ARCH__=300 -E -x c++  -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__  "-I/usr/local/cuda-10.1.243/bin/../targets/x86_64-linux/include"    -D__CUDACC_VER_MAJOR__=10 -D__CUDACC_VER_MINOR__=1 -D__CUDACC_VER_BUILD__=243 -include "cuda_runtime.h" -m64 "test.cu" > "/tmp/tmpxft_00002366_00000000-8_test.cpp1.ii" 
test.cu:2:10: fatal error: boost/regex.hpp: No such file or directory
 #include "boost/regex.hpp"
          ^~~~~~~~~~~~~~~~~
compilation terminated.

Note that CXXFLAGS contains the required -I$PREFIX/include and $PREFIX/include/boost/ exists:

CXXFLAGS=-fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I$PREFIX/include -fdebug-prefix-map=$SRC_DIR=/usr/local/src/conda/nvcc_linux-64-10.1 -fdebug-prefix-map=$PREFIX=/usr/local/src/conda-prefix -I/usr/local/cuda-10.1.243/include
pearu commented 5 years ago

nvcc seems to use ${CUDA_HOME}/bin/nvcc.profile for setting the required paths. A typical nvcc.profile contains

TOP              = $(_HERE_)/..
NVVMIR_LIBRARY_DIR = $(TOP)/nvvm/libdevice
LD_LIBRARY_PATH += $(TOP)/lib:
PATH            += $(TOP)/nvvm/bin:$(_HERE_):
INCLUDES        +=  "-I$(TOP)/$(_TARGET_DIR_)/include" $(_SPACE_)
LIBRARIES        =+ $(_SPACE_) "-L$(TOP)/$(_TARGET_DIR_)/lib$(_TARGET_SIZE_)/stubs" "-L$(TOP)/$(_TARGET_DIR_)/lib$(_TARGET_SIZE_)"
CUDAFE_FLAGS    +=
PTXAS_FLAGS     +=

I don't know yet if one can have a customized nvcc.profile that could be defined for conda environment. For instance, nvcc does not have an option to specify the path to nvcc.profile.

pearu commented 5 years ago

@isuruf , it seems to me that the set of environment flags CFLAGS, CPPFLAGS, CXXFLAGS, LDFLAGS is not sufficient for specifying include/library paths for nvcc compilation process. The C++ compiler specified in -ccbin (and for which CXXFLAGS is effective) is used later in the process but that will not help here as nvcc calls CPP on .cu file earlier.

So I think your "-1 on this PR" might be premature because the assumption that nvcc should use the mentioned environment flags may be wrong. What do you think?

Another approach would be to use

export CPLUS_INCLUDE_PATH=\${PREFIX}/include

(tested) but that would be equivalent to using -I option except that it would affect other compilers as well.

isuruf commented 5 years ago

Apparently, nvcc does not use CFLAGS, CPPFLAGS, CXXFLAGS, LDFLAGS.

gcc and clang don't use these either. It's the job of the build system of the package to pass these to the compiler and linker.

pearu commented 5 years ago

OK, I see your point, @isuruf .

pearu commented 5 years ago

Closing as the build system or the user has to specify the proper include directory options. For instance, when having test.cpp

#include <boost/regex.hpp>
int main() {
  return 0;
}

then all the following commands fail:

nvcc test.cpp
g++ test.cpp
clang++ test.cpp 

while all the following commands succeed:

nvcc -I$CONDA_PREFIX/include test.cpp
g++ -I$CONDA_PREFIX/include test.cpp
clang++ -I$CONDA_PREFIX/include test.cpp