sonots / cumo

Cumo (pronounced like "koomo") is CUDA aware numerical library whose interface is highly compatible with Ruby Numo
MIT License
93 stars 7 forks source link

multiple definition of `cumo_cuda_eCUDNNError' #147

Closed dpblnt closed 10 months ago

dpblnt commented 10 months ago

installing cumo-0.4.3 failed ...

/usr/local/lib64/ruby/gems/3.1.0/gems/cumo-0.4.3/3rd_party/mkmf-cu/bin/mkmf-cu-nvcc --mkmf-cu-ext=c -shared -o cumo.so cumo.o narray/narray.o narray/array.o narray/step.o narray/index.o narray/index_kernel.o narray/ndloop.o narray/ndloop_kernel.o narray/data.o narray/data_kernel.o narray/types/bit.o narray/types/int8.o narray/types/int16.o narray/types/int32.o narray/types/int64.o narray/types/uint8.o narray/types/uint16.o narray/types/uint32.o narray/types/uint64.o narray/types/sfloat.o narray/types/dfloat.o narray/types/scomplex.o narray/types/dcomplex.o narray/types/robject.o narray/types/bit_kernel.o narray/types/int8_kernel.o narray/types/int16_kernel.o narray/types/int32_kernel.o narray/types/int64_kernel.o narray/types/uint8_kernel.o narray/types/uint16_kernel.o narray/types/uint32_kernel.o narray/types/uint64_kernel.o narray/types/sfloat_kernel.o narray/types/dfloat_kernel.o narray/types/scomplex_kernel.o narray/types/dcomplex_kernel.o narray/types/robject_kernel.o narray/math.o narray/SFMT.o narray/struct.o narray/rand.o cuda/cublas.o cuda/driver.o cuda/memory_pool.o cuda/memory_pool_impl.o cuda/runtime.o cuda/nvrtc.o cuda/cudnn.o cuda/cudnn_impl.o -L. -L/usr/lib64 -L. -Wl,-O1 -Wl,--as-needed -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed -Wl,-O1 -Wl,--as-needed    -lruby31 -lcuda -ldl  -lm  -lc
gcc -shared -o cumo.so cumo.o narray/narray.o narray/array.o narray/step.o narray/index.o narray/index_kernel.o narray/ndloop.o narray/ndloop_kernel.o narray/data.o narray/data_kernel.o narray/types/bit.o narray/types/int8.o narray/types/int16.o narray/types/int32.o narray/types/int64.o narray/types/uint8.o narray/types/uint16.o narray/types/uint32.o narray/types/uint64.o narray/types/sfloat.o narray/types/dfloat.o narray/types/scomplex.o narray/types/dcomplex.o narray/types/robject.o narray/types/bit_kernel.o narray/types/int8_kernel.o narray/types/int16_kernel.o narray/types/int32_kernel.o narray/types/int64_kernel.o narray/types/uint8_kernel.o narray/types/uint16_kernel.o narray/types/uint32_kernel.o narray/types/uint64_kernel.o narray/types/sfloat_kernel.o narray/types/dfloat_kernel.o narray/types/scomplex_kernel.o narray/types/dcomplex_kernel.o narray/types/robject_kernel.o narray/math.o narray/SFMT.o narray/struct.o narray/rand.o cuda/cublas.o cuda/driver.o cuda/memory_pool.o cuda/memory_pool_impl.o cuda/runtime.o cuda/nvrtc.o cuda/cudnn.o cuda/cudnn_impl.o -L. -L/usr/lib64 -L. -Wl,-O1 -Wl,--as-needed -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed -Wl,-O1 -Wl,--as-needed -lruby31 -lcuda -ldl -lm -lc
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: narray/types/dfloat.o:(.bss+0x8): multiple definition of `cumo_cuda_eCudnnError'; narray/types/sfloat.o:(.bss+0x8): first defined here
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: narray/types/dfloat.o:(.bss+0x10): multiple definition of `cumo_cuda_eCUDNNError'; narray/types/sfloat.o:(.bss+0x10): first defined here
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: cuda/cudnn.o:(.bss+0x8): multiple definition of `cumo_cuda_eCUDNNError'; narray/types/sfloat.o:(.bss+0x10): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:475: cumo.so] Error 1
dpblnt commented 10 months ago

with this patch I was able to build

diff --git a/ext/cumo/extconf.rb b/ext/cumo/extconf.rb
index 63f9188..e56f732 100644
--- a/ext/cumo/extconf.rb
+++ b/ext/cumo/extconf.rb
@@ -53,6 +53,8 @@ $CXXFLAGS << " -std=c++14"
 #$CFLAGS=" $(cflags) -O3 -m64 -msse2 -funroll-loops"
 #$CFLAGS=" $(cflags) -O3"
 $INCFLAGS = "-Iinclude -Inarray -Icuda #{$INCFLAGS}"
+$LDFLAGS  << " -Wl,--allow-multiple-definition -lm -lc -lstdc++"
+

 $INSTALLFILES = Dir.glob(%w[include/cumo/*.h include/cumo/types/*.h include/cumo/cuda/*.h]).map{|x| [x,'$(archdir)'] }
 $INSTALLFILES << ['include/cumo/extconf.h','$(archdir)']