Hello everyone,
I have CFD code written in C/C++ that uses meson and ninja to build and install. For my thesis I’m trying to modify the code to allow it to use the GPU through openACC.
When I go to compile the code everything works, but when the linking happens I get this error:
I’ve not seen an undefined reference to “typeinfo” before, but doing a web search I found this on SO: c++ - g++ undefined reference to typeinfo - Stack Overflow
Seems to occur when a virtual function doesn’t have a definition. There’s a few other suggestions as well including a mismatch if RTTI was enabled or not. Doubt it would be this, but I’m not sure how the library is build, so possible.
-Mat
Hi Mat, thanks a lot for the reply.
I had already found this post but I don’t think that could be the problem. Indeed, in the basic version of the program in which the exact same libraries are present, using GCC the program is compiled and installed correctly.
I think, although I’m not sure, that the problem arises when the compiler is changed from GCC to NVC/NVC++ and meson is run to create the file (build.ninja) to pass to ninja.
-Link part from build.ninja created with GCC:
# Rules for linking.
rule STATIC_LINKER
command = rm -f $out && gcc-ar $LINK_ARGS $out $in
description = Linking static target $out
rule cpp_LINKER
command = c++ $ARGS -o $out $in $LINK_ARGS
description = Linking target $out
build SU2_CFD/src/SU2_CFD.p/SU2_CFD.cpp.o: cpp_COMPILER ../SU2_CFD/src/SU2_CFD.cpp
DEPFILE = SU2_CFD/src/SU2_CFD.p/SU2_CFD.cpp.o.d
DEPFILE_UNQUOTED = SU2_CFD/src/SU2_CFD.p/SU2_CFD.cpp.o.d
ARGS = -ISU2_CFD/src/SU2_CFD.p -ISU2_CFD/src -I../SU2_CFD/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c++11 -O3 -fPIC -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -Wno-error=cast-function-type -Wno-cast-function-type -Wno-error=stringop-truncation -Wno-stringop-truncation -Wno-error=missing-field-initializers -Wno-missing-field-initializers -Wno-error=class-memaccess -Wno-class-memaccess -DNDEBUG
build SU2_CFD/src/SU2_CFD: cpp_LINKER SU2_CFD/src/SU2_CFD.p/SU2_CFD.cpp.o | Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -Wl,--start-group SU2_CFD/src/libSU2core.a Common/src/libSU2Common.a -Wl,--end-group
build SU2_DOT/src/SU2_DOT.p/SU2_DOT.cpp.o: cpp_COMPILER ../SU2_DOT/src/SU2_DOT.cpp
DEPFILE = SU2_DOT/src/SU2_DOT.p/SU2_DOT.cpp.o.d
DEPFILE_UNQUOTED = SU2_DOT/src/SU2_DOT.p/SU2_DOT.cpp.o.d
ARGS = -ISU2_DOT/src/SU2_DOT.p -ISU2_DOT/src -I../SU2_DOT/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -ISU2_CFD/src -I../SU2_CFD/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c++11 -O3 -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -Wno-error=cast-function-type -Wno-cast-function-type -Wno-error=stringop-truncation -Wno-stringop-truncation -Wno-error=missing-field-initializers -Wno-missing-field-initializers -Wno-error=class-memaccess -Wno-class-memaccess -DNDEBUG
build SU2_DOT/src/SU2_DOT: cpp_LINKER SU2_DOT/src/SU2_DOT.p/SU2_DOT.cpp.o | Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -Wl,--start-group Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a -Wl,--end-group
build SU2_DEF/src/SU2_DEF.p/SU2_DEF.cpp.o: cpp_COMPILER ../SU2_DEF/src/SU2_DEF.cpp
DEPFILE = SU2_DEF/src/SU2_DEF.p/SU2_DEF.cpp.o.d
DEPFILE_UNQUOTED = SU2_DEF/src/SU2_DEF.p/SU2_DEF.cpp.o.d
ARGS = -ISU2_DEF/src/SU2_DEF.p -ISU2_DEF/src -I../SU2_DEF/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -ISU2_CFD/src -I../SU2_CFD/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c++11 -O3 -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -Wno-error=cast-function-type -Wno-cast-function-type -Wno-error=stringop-truncation -Wno-stringop-truncation -Wno-error=missing-field-initializers -Wno-missing-field-initializers -Wno-error=class-memaccess -Wno-class-memaccess -DNDEBUG
build SU2_DEF/src/SU2_DEF: cpp_LINKER SU2_DEF/src/SU2_DEF.p/SU2_DEF.cpp.o | Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -Wl,--start-group Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a -Wl,--end-group
build SU2_GEO/src/SU2_GEO.p/SU2_GEO.cpp.o: cpp_COMPILER ../SU2_GEO/src/SU2_GEO.cpp
DEPFILE = SU2_GEO/src/SU2_GEO.p/SU2_GEO.cpp.o.d
DEPFILE_UNQUOTED = SU2_GEO/src/SU2_GEO.p/SU2_GEO.cpp.o.d
ARGS = -ISU2_GEO/src/SU2_GEO.p -ISU2_GEO/src -I../SU2_GEO/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c++11 -O3 -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -Wno-error=cast-function-type -Wno-cast-function-type -Wno-error=stringop-truncation -Wno-stringop-truncation -Wno-error=missing-field-initializers -Wno-missing-field-initializers -Wno-error=class-memaccess -Wno-class-memaccess -DNDEBUG
build SU2_GEO/src/SU2_GEO: cpp_LINKER SU2_GEO/src/SU2_GEO.p/SU2_GEO.cpp.o | Common/src/libSU2Common.a
LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -Wl,--start-group Common/src/libSU2Common.a -Wl,--end-group
build SU2_SOL/src/SU2_SOL.p/SU2_SOL.cpp.o: cpp_COMPILER ../SU2_SOL/src/SU2_SOL.cpp
DEPFILE = SU2_SOL/src/SU2_SOL.p/SU2_SOL.cpp.o.d
DEPFILE_UNQUOTED = SU2_SOL/src/SU2_SOL.p/SU2_SOL.cpp.o.d
ARGS = -ISU2_SOL/src/SU2_SOL.p -ISU2_SOL/src -I../SU2_SOL/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -ISU2_CFD/src -I../SU2_CFD/src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c++11 -O3 -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -Wno-error=cast-function-type -Wno-cast-function-type -Wno-error=stringop-truncation -Wno-stringop-truncation -Wno-error=missing-field-initializers -Wno-missing-field-initializers -Wno-error=class-memaccess -Wno-class-memaccess -DNDEBUG
build SU2_SOL/src/SU2_SOL: cpp_LINKER SU2_SOL/src/SU2_SOL.p/SU2_SOL.cpp.o | Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -Wl,--start-group Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a -Wl,--end-group
-Link part from build.ninja created with NVC/NVC++:
# Rules for linking.
rule STATIC_LINKER
command = rm -f $out && ar $LINK_ARGS $out $in
description = Linking static target $out
rule cpp_LINKER
command = /opt/nvidia/hpc_sdk/Linux_x86_64/22.9/compilers/bin/nvc++ $ARGS -o $out $in $LINK_ARGS
description = Linking target $out
build SU2_CFD/src/SU2_CFD.p/SU2_CFD.cpp.o: cpp_COMPILER ../SU2_CFD/src/SU2_CFD.cpp
DEPFILE = SU2_CFD/src/SU2_CFD.p/SU2_CFD.cpp.o.d
DEPFILE_UNQUOTED = SU2_CFD/src/SU2_CFD.p/SU2_CFD.cpp.o.d
ARGS = -ISU2_CFD/src/SU2_CFD.p -ISU2_CFD/src -I../SU2_CFD/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -O3 -D_FILE_OFFSET_BITS=64 --c++11 -gpu=cc86,nordc -acc=gpu -Minfo=accel -pthread -fPIC -w -noswitcherror -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -DHAVE_GPU -DNDEBUG
build SU2_CFD/src/SU2_CFD: cpp_LINKER SU2_CFD/src/SU2_CFD.p/SU2_CFD.cpp.o | Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
LINK_ARGS = SU2_CFD/src/libSU2core.a Common/src/libSU2Common.a
build SU2_DOT/src/SU2_DOT.p/SU2_DOT.cpp.o: cpp_COMPILER ../SU2_DOT/src/SU2_DOT.cpp
DEPFILE = SU2_DOT/src/SU2_DOT.p/SU2_DOT.cpp.o.d
DEPFILE_UNQUOTED = SU2_DOT/src/SU2_DOT.p/SU2_DOT.cpp.o.d
ARGS = -ISU2_DOT/src/SU2_DOT.p -ISU2_DOT/src -I../SU2_DOT/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -ISU2_CFD/src -I../SU2_CFD/src -O3 -D_FILE_OFFSET_BITS=64 --c++11 -gpu=cc86,nordc -acc=gpu -Minfo=accel -pthread -w -noswitcherror -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -DHAVE_GPU -DNDEBUG
build SU2_DOT/src/SU2_DOT: cpp_LINKER SU2_DOT/src/SU2_DOT.p/SU2_DOT.cpp.o | Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
LINK_ARGS = Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
build SU2_DEF/src/SU2_DEF.p/SU2_DEF.cpp.o: cpp_COMPILER ../SU2_DEF/src/SU2_DEF.cpp
DEPFILE = SU2_DEF/src/SU2_DEF.p/SU2_DEF.cpp.o.d
DEPFILE_UNQUOTED = SU2_DEF/src/SU2_DEF.p/SU2_DEF.cpp.o.d
ARGS = -ISU2_DEF/src/SU2_DEF.p -ISU2_DEF/src -I../SU2_DEF/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -ISU2_CFD/src -I../SU2_CFD/src -O3 -D_FILE_OFFSET_BITS=64 --c++11 -gpu=cc86,nordc -acc=gpu -Minfo=accel -pthread -w -noswitcherror -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -DHAVE_GPU -DNDEBUG
build SU2_DEF/src/SU2_DEF: cpp_LINKER SU2_DEF/src/SU2_DEF.p/SU2_DEF.cpp.o | Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
LINK_ARGS = Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
build SU2_GEO/src/SU2_GEO.p/SU2_GEO.cpp.o: cpp_COMPILER ../SU2_GEO/src/SU2_GEO.cpp
DEPFILE = SU2_GEO/src/SU2_GEO.p/SU2_GEO.cpp.o.d
DEPFILE_UNQUOTED = SU2_GEO/src/SU2_GEO.p/SU2_GEO.cpp.o.d
ARGS = -ISU2_GEO/src/SU2_GEO.p -ISU2_GEO/src -I../SU2_GEO/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -O3 -D_FILE_OFFSET_BITS=64 --c++11 -gpu=cc86,nordc -acc=gpu -Minfo=accel -pthread -w -noswitcherror -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -DHAVE_GPU -DNDEBUG
build SU2_GEO/src/SU2_GEO: cpp_LINKER SU2_GEO/src/SU2_GEO.p/SU2_GEO.cpp.o | Common/src/libSU2Common.a
LINK_ARGS = Common/src/libSU2Common.a
build SU2_SOL/src/SU2_SOL.p/SU2_SOL.cpp.o: cpp_COMPILER ../SU2_SOL/src/SU2_SOL.cpp
DEPFILE = SU2_SOL/src/SU2_SOL.p/SU2_SOL.cpp.o.d
DEPFILE_UNQUOTED = SU2_SOL/src/SU2_SOL.p/SU2_SOL.cpp.o.d
ARGS = -ISU2_SOL/src/SU2_SOL.p -ISU2_SOL/src -I../SU2_SOL/src -I../externals/CLI11 -I../externals/mel -ICommon/src -I../Common/src -ISU2_CFD/src -I../SU2_CFD/src -O3 -D_FILE_OFFSET_BITS=64 --c++11 -gpu=cc86,nordc -acc=gpu -Minfo=accel -pthread -w -noswitcherror -Wno-empty-body -Wno-unused-parameter -Wno-deprecated-declarations -DHAVE_GPU -DNDEBUG
build SU2_SOL/src/SU2_SOL: cpp_LINKER SU2_SOL/src/SU2_SOL.p/SU2_SOL.cpp.o | Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
LINK_ARGS = Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
In the GNU link rule, you’re passing several linker flags (i.e. the ones that start with “-Wl,”). I’m not sure they’re necessary, but you should try using the same rule for the NVHPC link.
build SU2_DOT/src/SU2_DOT: cpp_LINKER SU2_DOT/src/SU2_DOT.p/SU2_DOT.cpp.o | Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a
LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -Wl,--start-group Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a -Wl,--end-group
Otherwise, I’m not sure and would need a reproducing example to determine the cause.
To reproduce:
- Dowload CFD program https://github.com/su2code/SU2/releases/tag/v7.4.0
- Substitute meson.py file with meson.py (3.4 KB)
- Substitute meson.build with meson.build (10.6 KB) and meson_option.txt with meson_options.txt (3.0 KB)
- Go to solvers folder
cd SU2_CFD/src/solvers
and substitute CEulerSolver.cpp with CEulerSolver.cpp (382.8 KB) - Inside SU2 folder run
CC=nvc CXX=nvc++ ./meson.py build_gpu -Denable-autodiff=false -Dwith-mpi=disabled -Denable-tecio=false -Denable-cgns=false -Denable-gpu=true --prefix=/home/user/something/SU2
- Run
./ninja -C build install
Thank you very much for the help
He’s what I did:
I first downloaded the “src” package from the v7.4.0 page, but the meson script failed. Looks like it’s expecting the package to be a git repo. Hence, I instead cloned the SU2 repo and then was able to get meson working.
I then needed to change “./ninja -C build install” to “./ninja -C build_gpu install” since no “build” directory existed.
From there I did see the undefined references, though many more than what you show in your post. These were caused by the order in which the libraries appear on the link. Switching the order to “Common/src/libSU2Common.a SU2_CFD/src/libSU2core.a”, fixed the issue.
Since I’m not reproducing using your exact step, and I get slightly different errors, I can’t be sure switching the library order will fix your issue, but let’s give it a try.
-Mat
Correct
Really a huge thank you, you saved me.
Now ninja compile and link the program correctly, but a problem appear when i try to run the program
When i build the program i use this flags
Hmm, might be because you’re compiling with “-gpu=ccnative” but don’t have the flag on the link like.
Though unless you really need to compile to multiple targets, I’d suggest removing “-gpu=ccnative” and have the compiler target the device on this system (default).
I’ve tried both adding (to the link) and excluding (from compiler and link) -gpu=ccnative
but I always get the same error when I try to run the program.
This type of error typically occurs when there’s a mismatch between the target device the binary was compiled for and the device being run. Though I’m not sure why it would occur here. What’s the output from the command “nvaccelinfo”?
While I doubt this problem, it’s possible that it’s an RDC issue. Try compiling and linking with “-gpu=nordc”. Typically this is only needed when linking with a different compiler since RDC requires a device link step, but maybe the use in the static library is causing an issue. I’ve never had an issue putting OpenACC code in static libraries before and why I’m skeptical that is this is the issue, but worth a try.
FYI, when you do get past this issue, it’s highly likely that you’ll get a runtime error since it doesn’t appear that you’re using data directives to handle the deep copy to the device of the aggregate data types. I’d suggest that at least initially you use CUDA Unified Memory (i.e. add the flag “-gpu=managed”) so all allocated data is managed by the CUDA driver. All static data does still need to be managed through data directive or implicitly by the compiler.
Hi Mat,
this is the output of nvaccelinfo
:
CUDA Driver Version: 11070
NVRM version: NVIDIA UNIX x86_64 Kernel Module 515.86.01 Wed Oct 26 09:12:38 UTC 2022
Device Number: 0
Device Name: NVIDIA GeForce RTX 3060 Laptop GPU
Device Revision Number: 8.6
Global Memory Size: 6235422720
Number of Multiprocessors: 30
Concurrent Copy and Execution: Yes
Total Constant Memory: 65536
Total Shared Memory per Block: 49152
Registers per Block: 65536
Warp Size: 32
Maximum Threads per Block: 1024
Maximum Block Dimensions: 1024, 1024, 64
Maximum Grid Dimensions: 2147483647 x 65535 x 65535
Maximum Memory Pitch: 2147483647B
Texture Alignment: 512B
Clock Rate: 1425 MHz
Execution Timeout: Yes
Integrated Device: No
Can Map Host Memory: Yes
Compute Mode: default
Concurrent Kernels: Yes
ECC Enabled: No
Memory Clock Rate: 7001 MHz
Memory Bus Width: 192 bits
L2 Cache Size: 3145728 bytes
Max Threads Per SMP: 1536
Async Engines: 2
Unified Addressing: Yes
Managed Memory: Yes
Concurrent Managed Memory: Yes
Preemption Supported: Yes
Cooperative Launch: Yes
Multi-Device: Yes
Default Target: cc86
Whit addition of -gpu=nordc
, everything seems to work perfectly and I no longer get any error messages
when I launch the program.
A big thanks!!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.