NVCC, strange interaction with -Xcompiler - c++

I'm trying to build Magma and I'm running into problems which I'm pretty sure I didn't run into when using earlier versions of CUDA. (I'm using 6.5 now). What happens is that the makefile generates the following command:
nvcc -fPIC -O3 -DADD_ -Xcompiler -fno-strict-aliasing -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_35,code=compute_35 -I/opt/cuda/include -I../include -I../control -I../sparse-iter/include -c zgemv_conjv.cu -o zgemv_conjv.o
nvcc fatal : Unknown option 'fPIC'
Googling shows that -fPIC should be used only with -Xcompiler because it's not an nvcc option. But as you can see I do have -Xcompiler in my nvcc command.
I tried putting -fPIC behind -Xcompiler like this:
nvcc -O3 -DADD_ -Xcompiler -fPIC -fno-strict-aliasing -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_35,code=compute_35 -I/opt/cuda/include -I../include -I../control -I../sparse-iter/include -c zgemv_conjv.cu -o zgemv_conjv.o
nvcc fatal : Unknown option 'fno-strict-aliasing'
It fails on the next non-nvcc option, even though it is behind -Xcompiler. What works is this:
nvcc -O3 -DADD_ -Xcompiler -fno-strict-aliasing -Xcompiler -fPIC -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_35,code=compute_35 -I/opt/cuda/include -I../include -I../control -I../sparse-iter/include -c zgemv_conjv.cu -o zgemv_conjv.o
Where I have duplicated -Xcompiler switch.
Does anyone know if this is the intended behaviour? I couldn't find any reference or documentaion regarding it, and I'm pretty sure it didn't use to work like that in previous versions of CUDA. Could it be a bug?

According to this, you have to separate your different -Xcompiler sub-options with a comma or you have to use for each option a separate -Xcompiler, like you did in your last try. It looks like this is intended.

Related

compile simple github fails at ext submodule

i am trying to compile this git https://github.com/yapb/yapb locally
i am using ubuntu 64bit, and it says i must compile 32bit
i am using now
CC=clang CXX=clang meson build-clang
but get this error
FAILED: yapb.so.p/src_chatlib.cpp.o
clang -Iyapb.so.p -I. -I.. -fvisibility=hidden -flto
-fcolor-diagnostics -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall
-Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -Werror -std=c++14
-fno-exceptions -O3 -DVERSION_GENERATED -fno-threadsafe-statics
-fno-exceptions -fno-rtti -m32 -pedantic -fdata-sections
-ffunction-sections -mtune=generic -fno-builtin -funroll-loops
-fomit-frame-pointer -fno-stack-protector -fvisibility=hidden
-fvisibility-inlines-hidden -msse2 -mfpmath=sse -fPIC
-isystem../ext/crlib -isystem../ext -isystem../inc -isystem..
-isystem. -MD -MQ yapb.so.p/src_chatlib.cpp.o -MF
yapb.so.p/src_chatlib.cpp.o.d -o yapb.so.p/src_chatlib.cpp.o -c
../src/chatlib.cpp
In file included from ../src/chatlib.cpp:8:
In file included from ../inc/yapb.h:10:
In file included from ../ext/hlsdk/extdll.h:28:
In file included from ../ext/crlib/crlib/string.h:17:
../ext/crlib/crlib/array.h:15:10: fatal error: 'initializer_list' file not found
#include <initializer_list>```
Double-check the pre-requisites mentioned in YaPB Building the Bot page.
Try and open a regular CMD (instead of Powershell), making sure it inherits all your previous setups (meaning its %PATH% does reference g++.exe, pip.exe, and so on.

How to use linked libraries compiled with libc++ libstdc++ mixed

I am trying to write a script that uses a library compiled with clang and another library compiled with G++, I get the following error:
ld.lld: error: undefined symbol: myFunction()
Which (according to this Difference between string and char[] types in C++) is apparently due to std::string meaning different things in different versions of G++ and clang.
Does this mean I have to rewrite the Makefile of my target library to use the same version of G++/Clang? Because that seems like an awful amount of effort just to link a prewritten library, and I think I must be missing something here.
More info
I am compiling v8_shell using ninja -C out/debug
defines = -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_X11=1 -DNO_TCMALLOC -DMEMORY_TOOL_REPLACES_ALLOCATOR -DMEMORY_SANITIZER_INITIAL_SIZE -DADDRESS_SANITIZER -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DCHROMIUM_BUILD -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -DCR_CLANG_REVISION=\"353250-1\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DCOMPONENT_BUILD -D_LIBCPP_ABI_UNSTABLE -D_LIBCPP_ABI_VERSION=Cr -DCR_LIBCXX_REVISION=349080 -DCR_LIBCXXABI_REVISION=347903 -D_LIBCPP_ENABLE_NODISCARD -DCR_SYSROOT_HASH=e7c53f04bd88d29d075bfd1f62b073aeb69cbe09 -D_DEBUG -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -DENABLE_DISASSEMBLER -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -DENABLE_GDB_JIT_INTERFACE -DENABLE_MINOR_MC -DOBJECT_PRINT -DVERIFY_HEAP -DV8_TRACE_MAPS -DV8_ENABLE_ALLOCATION_TIMEOUT -DV8_ENABLE_FORCE_SLOW_PATH -DV8_INTL_SUPPORT -DENABLE_HANDLE_ZAPPING -DV8_USE_SNAPSHOT -DV8_USE_EXTERNAL_STARTUP_DATA -DV8_CONCURRENT_MARKING -DV8_CHECK_MICROTASKS_SCOPES_CONSISTENCY -DV8_EMBEDDED_BUILTINS -DV8_ENABLE_CHECKS -DV8_DEPRECATION_WARNINGS -DV8_IMMINENT_DEPRECATION_WARNINGS -DV8_TARGET_ARCH_X64 -DDEBUG -DDISABLE_UNTRUSTED_CODE_MITIGATIONS -DUSING_V8_SHARED -DV8_ENABLE_CHECKS -DV8_DEPRECATION_WARNINGS -DV8_IMMINENT_DEPRECATION_WARNINGS -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DUSE_CHROMIUM_ICU=1 -DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE -DUCHAR_TYPE=uint16_t -DUSING_V8_BASE_SHARED -DUSING_V8_PLATFORM_SHARED
include_dirs = -I../.. -Igen -I../.. -Igen -I../../include -Igen/include -I../../third_party/icu/source/common -I../../third_party/icu/source/i18n -I../../include
cflags = -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -funwind-tables -fPIC -B../../third_party/binutils/Linux_x64/Release/bin -pthread -fcolor-diagnostics -fmerge-all-constants -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -fcomplete-member-pointers -m64 -march=x86-64 -Wall -Werror -Wextra -Wimplicit-fallthrough -Wthread-safety -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-unneeded-internal-declaration -Wno-undefined-var-template -Wno-ignored-pragma-optimize -fno-omit-frame-pointer -g2 -gsplit-dwarf -ggnu-pubnames -gcolumn-info -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-blacklist=../../tools/memory/asan/blacklist.txt -fvisibility=hidden -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wmissing-field-initializers -Wextra-semi -Winconsistent-missing-override -Wunreachable-code -Wshorten-64-to-32 -O2 -fno-ident -fdata-sections -ffunction-sections
cflags_cc = -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -std=c++14 -fno-exceptions -fno-rtti -nostdinc++ -isystem../../buildtools/third_party/libc++/trunk/include -isystem../../buildtools/third_party/libc++abi/trunk/include --sysroot=../../build/linux/debian_sid_amd64-sysroot -fvisibility-inlines-hidden
label_name = v8_shell
target_out_dir = obj
target_output_name = v8_shell
build obj/v8_shell/shell.o: cxx ../../samples/shell.cc || obj/generate_bytecode_builtins_list.stamp obj/run_torque.stamp obj/v8_dump_build_config.stamp obj/src/inspector/protocol_generated_sources.stamp obj/third_party/icu/icudata.stamp
build ./v8_shell: link obj/v8_shell/shell.o obj/build/config/sanitizers/liboptions_sources.a | ./libv8.so.TOC ./libv8_libbase.so.TOC ./libv8_libplatform.so.TOC ./libicui18n.so.TOC ./libicuuc.so.TOC ./libc++.so.TOC || obj/build/win/default_exe_manifest.stamp obj/v8_dump_build_config.stamp obj/build/config/executable_deps.stamp
ldflags = -pie -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,relro -fuse-ld=lld -Wl,--color-diagnostics -m64 -Werror -Wl,--gdb-index -rdynamic -nostdlib++ --sysroot=../../build/linux/debian_sid_amd64-sysroot -L../../build/linux/debian_sid_amd64-sysroot/usr/local/lib/x86_64-linux-gnu -Wl,-rpath-link=../../build/linux/debian_sid_amd64-sysroot/usr/local/lib/x86_64-linux-gnu -L../../build/linux/debian_sid_amd64-sysroot/lib/x86_64-linux-gnu -Wl,-rpath-link=../../build/linux/debian_sid_amd64-sysroot/lib/x86_64-linux-gnu -L../../build/linux/debian_sid_amd64-sysroot/usr/lib/x86_64-linux-gnu -Wl,-rpath-link=../../build/linux/debian_sid_amd64-sysroot/usr/lib/x86_64-linux-gnu -fsanitize=address -fsanitize-address-use-after-scope -pie -Wl,-rpath-link=. -Wl,--disable-new-dtags -Wl,-rpath=\$$ORIGIN/. -Wl,-rpath-link=. -Wl,-O2 -Wl,--gc-sections -Wl,-u_sanitizer_options_link_helper -fsanitize=address -fsanitize-address-use-after-scope
libs = -L . -ldl -lpthread -lrt
output_extension =
output_dir = .
solibs = ./libtester.so ./libv8.so ./libv8_libbase.so ./libv8_libplatform.so ./libicui18n.so ./libicuuc.so ./libc++.so
Link to code is here:
https://github.com/v8/v8/blob/master/samples/shell.cc
All I have done is add a test library that returns a std::string and this is called from shell.cc.
This test library is compiled with
clang++ -shared -o libtester tester.cpp -fPIC -L . -lpthread
Which yields undefined symbol errors.
I can get it to compile by forcing libc++ that v8 seems to use, but then I get a whole host of core dumps and other errors at runtime, so I don't think thats a legitimate fix.
clang++ -shared -o libtester.so tester.cpp -fPIC -std=c++11 -L . -stdlib=libc++ -lpthread
Example code snippet:
tester.cpp
std::string myFunction() {
std::string newstring;
// do something
return newstring;
}
shell.cc
std::string test = myFunction();
cout << test;
Update please see these posts that document it further C++ Undefined symbol related to std::string in static lib
Can't link libFuzzer.a using clang with libc++
Theres no real answer apart from use libstdc++ rather than libc++ for everything, but thats not really an option to convert an entire project like v8 to libstdc++
The build recipe you use for V8 builds it with -D_LIBCPP_ABI_UNSTABLE -D_LIBCPP_ABI_VERSION=Cr -DCR_LIBCXX_REVISION=349080 -DCR_LIBCXXABI_REVISION=347903. According to libc++ ABI stability, these macros affect the library ABI. Your separate compilation uses just -stdlib=libc++, so it does not enable the incompatible ABI.
You might get better results if you use a different recipe for building V8, something that uses the system C++ standard library with its default (stable) ABI.
This is the solution for compiling v8 with libstdc++.
Type the following command
gn args out/stdc
Add the following arguments to the args file:
is_clang = true
use_custom_libcxx_for_host=false
use_custom_libcxx=false
libcxx_abi_unstable=false
Build with
ninja -C out/stdc

Get list of created files by clang

Is there any way to get a list of files clang created for my source file? I have a very complex and long command line call for clang (actually from Xcode), and I would like to know which files get created besides temporary object files:
(FYI: I had to shorten the call due to SO)
clang++ -x c++
-arch
x86_64
-fmessage-length=0
-fdiagnostics-show-note-include-stack
-fmacro-backtrace-limit=0
-std=gnu++14
-stdlib=libc++
-fmodules
-gmodules
-fmodules-cache-path=/Users/Daniel/Library/Developer/Xcode/DerivedData/ModuleCache.noindex
-fmodules-prune-interval=86400
-fmodules-prune-after=345600
-fbuild-session-file=/Users/Daniel/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation
-fmodules-validate-once-per-build-session
-Wnon-modular-include-in-framework-module
-Werror=non-modular-include-in-framework-module
-Wno-trigraphs
-fpascal-strings
-O0
-DDEBUG=1
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
-fasm-blocks
-fstrict-aliasing
-Wdeprecated-declarations
-Winvalid-offsetof
-mmacosx-version-min=10.14
-g
-fvisibility-inlines-hidden
-Wno-sign-conversion
-index-store-path
/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Index/DataStore
-iquote
/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Intermediates.noindex/afds.build/Debug/afds.build/afds-generated-files.hmap
-I/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Intermediates.noindex/afds.build/Debug/afds.build/afds-own-target-headers.hmap
-I/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Intermediates.noindex/afds.build/Debug/afds.build/afds-all-target-headers.hmap
-iquote
/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Intermediates.noindex/afds.build/Debug/afds.build/afds-project-headers.hmap
-I/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Products/Debug/include
-I/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Intermediates.noindex/afds.build/Debug/afds.build/DerivedSources/x86_64
-I/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Intermediates.noindex/afds.build/Debug/afds.build/DerivedSources
-F/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Products/Debug
-MMD
-MT
dependencies
-MF
/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Intermediates.noindex/afds.build/Debug/afds.build/Objects-normal/x86_64/main.d
--serialize-diagnostics
/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Intermediates.noindex/afds.build/Debug/afds.build/Objects-normal/x86_64/main.dia
-c
/Users/Daniel/Desktop/afds/afds/main.cpp
-o
/Users/Daniel/Library/Developer/Xcode/DerivedData/afds-a7sdf68ads76f8asd7f6/Build/Intermediates.noindex/afds.build/Debug/afds.build/Objects-normal/x86_64/main.o

How to use Clang's CUDA compiler?

I am on Ubuntu 17.10. I installed the CUDA 9.1 SDK from NVIDIA.
This is what I tried:
~/GrinGoldMiner/src/Cudacka$ clang++-5.0 -Wl,--cuda-path=/usr/local/cuda-9.1 kernel.cu
clang: error: cannot find libdevice for sm_20. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice.
clang: error: cannot find CUDA installation. Provide its path via --cuda-path, or pass -nocudainc to build without CUDA includes.
clang: error: cannot find CUDA installation. Provide its path via --cuda-path, or pass -nocudainc to build without CUDA includes.
Obviously it doesn't work. It seems like the linker flags are not getting passed. How can I pass them correctly?
It seems clang++-5.0 does not support CUDA 9.X ...
clang++ is able to compile CUDA kernels with CUDA 8.0:
$ clang++-5.0 -O0 -g --cuda-gpu-arch=sm_50 --cuda-path=/usr/local/cuda-8.0 -o t1 t1.cu -L/usr/local/cuda-8.0/lib64 -lcudart
But when using CUDA 9.X I get the same error as you:
$ clang++-5.0 --cuda-gpu-arch=sm_50 --cuda-path=/usr/local/cuda-9.0 -o t1 t1.cu -L/usr/local/cuda-9.0/lib64 -lcudart
clang: error: cannot find libdevice for sm_50. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice.
They added support for Volta (sm_70) and CUDA 9.0 in this commit: 6d4cb40.
In 2017, this was only available on master branch, and you would have confirmed it like this:
$ git clone https://github.com/llvm-mirror/clang.git
$ cd clang/
$ git branch --contains 6d4cb40
* master
$ git checkout release_50
Branch release_50 set up to track remote branch release_50 from origin.
Switched to a new branch 'release_50'
$ git log | grep 6d4cb40
$ (output was empty)
Note that clang (7.0.0, released September 2018) supports CUDA 7.0 through 9.2.
I tried to build the GrinGoldMiner's Cudacka under Ubuntu 17.10, and all I had to do was:
make
This generated two commands on my machine (after some cleanup):
/usr/local/cuda-9.1/bin/nvcc -ccbin g++ -m64 -Xcompiler -fpermissive -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -o cudacka.o -c kernel.cu
/usr/local/cuda-9.1/bin/nvcc -ccbin g++ -m64 -Xcompiler -fpermissive -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -o Cudacka.exe cudacka.o
And they finished successfully generating executable Cudacka.exe.
If you are interested specifically in clang:
When I tried to replace g++ with clang++-5.0, I got this error:
nvcc fatal : The version ('50000') of the host compiler ('clang') is not supported
If I use -std=c++11 -ccbin clang++ instead of -ccbin g++, I get this error:
kernel.cu(397): error: explicit instantiation definition directive for __global__ functions with clang host compiler is not yet supported
So, I doubt that you can use clang to compile that code for Ubuntu.

using other c++ compiler to compile the CUDA code

I have a CUDA (*.cu) code compiled by nvcc, which is working pretty good in GPU. But nvcc doesn't support some c++11 features and some 3rd party c++ library cannot be used with nvcc. I wonder if it is possible to compile the .cu code with gcc or other commercial c++ compiler? Thanks.
nvcc supports explicitly specifying the host compiler it uses, togather with the host-compiler-specific options. You could find the doc on nvcc options -ccbin and -Xcompiler for details.
http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#nvcc-command-options
For example, I bind nvcc with Intel compiler and Intel MKL as follows.
$ nvcc -ftz true -ccbin icpc -Xcompiler "-Wall -Wno-long-long -ansi -pedantic -ansi-alias -parallel -fopenmp -openmp-link=static -static-intel -wd10237" -O2 -Xcompiler "-O2" -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -Ilib -c -o test/triangle.o test/triangle.cu
$ nvcc -ftz true -ccbin icpc -Xcompiler "-Wall -Wno-long-long -ansi -pedantic -ansi-alias -parallel -fopenmp -openmp-link=static -static-intel -wd10237" -O2 -Xcompiler "-O2" -Ilib -Llib test/triangle.o lib/KTiming.o -lpthread -lm /opt/intel/composer_xe_2013.1.117/mkl/lib/intel64/libmkl_intel_lp64.a /opt/intel/composer_xe_2013.1.117/mkl/lib/intel64/libmkl_intel_thread.a /opt/intel/composer_xe_2013.1.117/mkl/lib/intel64/libmkl_core.a /opt/intel/composer_xe_2013.1.117/mkl/lib/intel64/libmkl_core.a -lcublas -lcurand -lcusparse -o test/triangle