Using OpenACC with compiled C programs - openacc

I am trying to use OpenACC to accelerate the Samtools package by inserting pragmas at the applicable for loops.
linux86-64/19.4/bin/pgcc -acc autopar -ta=tesla config.h stats.c
I get the following error message:
stats.c:
PGC-F-0206-Can't find include file config.h (stats.c: 41)
PGC/x86-64 Linux 19.4-0: compilation aborted
I checked and the config.h file is in the same directory as the stats.c file. So I'm not sure how to resolve this error so that I can GPU accelerate samtools.
I've also tried to install samtools after adding the pragmas to the stats.c program but I am not seeing a difference in acceleration. I also check if GPU is being utilized during the run, for instance when I use samtools sort and no GPUs appear to be used.

Related

Makefile from Cmake is not putting actual compilers rather it puts 'ftn' which is used as a variable for CMAKE_Fortran_COMPILER

I have been trying to compile a large Fortran code with many files in it on a HPC with the use of CMake. CMake properly configures and generates a Makefile. While Making, I get an error saying '/bin/sh: ftn: command not found'. The Makefile tries to compile the code like this->
ftn -o CMakeFiles/s3d.x.dir/modules/param_m.f90.o
When I compile it on my personal system or another HPC, it goes like->
mpif90 -o CMakeFiles/s3d.x.dir/modules/param_m.f90.o
I don't know why CMake is not able to put actual compilers in place of 'ftn'.
I would really appreciate if any suggestions come up.

How to preprocess OpenCL kernel?

Its simple to call the preprocessor on a c/c++ code:
g++ -E <file>.cpp
And it passes through the preprocessor and generates the preprocessed code.
I have OpenCL kernel in .cl how to achieve the same?
This is what I did and failed:
g++ -E -I. -std=c++11 -g -O3 -march=native -I/path/to/opencl/include/ -Wno-unused-result kernel.cl -L/path/to/opencl/lib/x86_64/ -lOpenCL -lquadmath
g++: warning: kernel.cl: linker input file unused because linking not done
Thanks
OpenCL code can run on a different architecture to the one that you are using to compile this on. You might find that there are differences depending on the complile time settings in the code that depend on the physical configuration of the target.
The most reliable method for generation of the postprocessed code for AMD devices is to ask the framework to save the temporary files, including the postprocessed output files.
On linux all you need to do for AMD is set an environment varisable. ie:
export AMD_OCL_BUILD_OPTIONS_APPEND="-save-temps"
When you compile you opencl program you will see a few files in /tmp. The one with the .i extension is the postprocessed file. This might be different to the one that you will get using cpp on the host architecture.

How to list failed targets after building boost?

I am building boost on my windows using mingw-4.8.1 and have a few targets which failed. My Problem is that, I do not know which specific targets failed and which were skipped.
Is there a way to list the failed/skipped targets after the build is completed?
Here the console output:
...failed updating 20 targets...
...skipped 28 targets...
...updated 5789 targets...
Commands used after downloading a unzipping boost:
bootstrap
once b2.exe is built. I execute the following command in cmd
b2 -j4 --build-dir=build toolset=gcc --build-type=complete --stagedir=C:\SW\Boost -sNO_BZIP2=1
System: Windows 7 ( intel i5 vPro)
Compiler: gcc (mingw 4.8.1)
Boost: boost 1.61.0
I had the same problem. After some research, I found this is the best way to see where it got failed.
My error messages (depends on your machine, you may see different ones):
...failed updating 6 targets...
...skipped 6 targets...
...updated 1092 targets...
I run ./b2 -q
This will stop at your first errors, in my case:
gcc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.8.3/release/threading-multi/bzip2.o
libs/iostreams/src/bzip2.cpp:20:56: fatal error: bzlib.h: No such file or directory
#include "bzlib.h" // Julian Seward's "bzip.h" header.
^
compilation terminated.
"g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pthread -fPIC -m64 -DBOOST_ALL_NO_LIB=1 -DBOOST_IOSTREAMS_DYN_LINK=1 -DBOOST_IOSTREAMS_USE_DEPRECATED -DNDEBUG -I"." -c -o "bin.v2/libs/iostreams/build/gcc-4.8.3/release/threading-multi/bzip2.o" "libs/iostreams/src/bzip2.cpp"
...failed gcc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.8.3/release/threading-multi/bzip2.o...
...failed updating 1 target...
Then you can install the missing dependencies, and see your second missing ones.
To see every single one of your errors, you need to install dependencies on after
another. This is good, if you are determined to make a full boost build.
In my case, I compiled bzip library http://www.bzip.org/downloads.html.
This library is tricky to make. Boost needs the dynamic version on Linux.
make -f Makefile-libbz2_so
You have to manually copy the libbz2.so.1.0.6 file to /usr/local/lib
The make two symbolic links
libbz2.so.1 -> libbz2.so.1.0.6
libbz2.so -> libbz2.so.1
After this my boost can be made and I saw:
The Boost C++ Libraries were successfully built!
Or try ./b2 -s NO_BZIP2=1 to skip
So, a little bit of more research resulted in the following.
One can get the build configuration and other build output using
b2 [options]
b2 --help reveals the options that can be used. I used the following approaches to diagnose exactly which targets were failing or getting skipped.
Approach 1
As suggested by #JanHenke in comments, I ran the same command
b2 -j4 --build-dir=build toolset=gcc --build-type=complete --stagedir=C:\SW\Boost -sNO_BZIP2=1
(as mentioned in question) again.
Result: All tragets that are already built are skipped and only failed ones are shown.
Problem: If there are many targets which failed then this just floods the console and it is difficult to find out what is going on.
Approach 2
Run the command (see 1) and select all from the command prompt using right mouse click, and then click gain to copy and paste it in a text editor so that is searchable.
Result: Usable insights can be drawn by searching for failed or error keywords
Problem: Still not the optimal way as not all the info is vailable on the current cmd window.
Approach 3
Not Done as for me 2. worked, but should surely work
Create a batchfile where in, the command is written and all that is printed on the cmd window, gets logged in a text file using the > or >> operators.
Result: Will be the best way (known to me till now) to know which exact targets are getting failed and a proper diagnostic action can be taken.
PS: I found that the there is a bug when trying to build serialization library with MinGW. Below the error I am facing and a link to boost forum which talks about the same error.
gcc.compile.c++ build\boost\bin.v2\libs\serialization\build\gcc-mingw-4.8.1\debug\xml_woarchive.o
In file included from ./boost/archive/detail/utf8_codecvt_facet.hpp:23:0,
from ./boost/archive/impl/xml_woarchive_impl.ipp:34,
from libs\serialization\src\xml_woarchive.cpp:28:
./boost/detail/utf8_codecvt_facet.hpp:116:30: error:
function 'boost::archive::detail::utf8_codecvt_facet::utf8_codecvt_facet(std::size_t)'
definition is marked dllimport
More info Reference1 and Reference2.
Sadly have not found a solution for it yet. Also, it is not the scope of this question.

Cross compiling kernel, using Makefile. How to suppress -Wunused-but-set-variable warning

I'm trying to Cross compile a kernel for Android using Ubuntu.
After successfully setting up the menuconfig, and compiling with the following option:
make ARCH=arm CROSS_COMPILE="arm-bravo-" -i -j10
It starts building, but then terminates with a lot of these errors:
error: variable '*something*' set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
Now I understand that this can be fixed by running gcc with --disable-werror option. Probem is that this is a huge project (kernel) and I am not well versed enough with make and Makefile, to know where I have to set this value. Kindly help me understand and fix this problem.
After weeks, I'm now in a position to answer my own question..
Look for KBUILD_CFLAGS in the main Makefile, and add the following to suppress warnings as errors:
KBUILD_CFLAGS += -w
// if all errors are to be suppressed
KBUILD_CFLAGS += -Wno-error=unused-but-set-variable
// if that specific error is to be suppressed.

Passing a gcc flag through makefile

I am trying to build a pass using llvm and I have finished building llvm and its associated components. However, when I run make after following all the steps to build a pass including the makefile, I get the following
relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
After tyring to find a fix by googling the error message, I came to know that this is not specific to llvm. A few solutions suggested that I should use "--enable-shared" while running configure but that didn't help my case. Now I want to re-build llvm using fPIC, as the error says. But how do I do this using the makefile?
Looks like you could add the -fPIC (for position-independent code, something you want for a shared library that could be loaded at any address) by setting shell variables:
export CFLAGS="$CFLAGS -fPIC"
export CXXFLAGS="$CXXFLAGS -fPIC"
Looking at Makefile.rules, these will be picked up and used. Seems strange that it wasn't there to begin with.
EDIT:
Actually, reading more in the makefiles, I found this link to the LLVM Makefile Guide. From Makefile.rules, setting either SHARED_LIBRARY=1 or LOADABLE_MODULE=1 (which implies SHARED_LIBRARY) in Makefile will put -fPIC in the compiler flags.
If you are moderately convinced that you should use '-fPIC' everywhere (or '-m32' or '-m64', which I need more frequently), then you can use the 'trick':
CC="gcc -fPIC" ./configure ...
This assumes a Bourne/Korn/POSIX/Bash shell and sets the environment variable CC to 'gcc -fPIC' before running the configure script. This (usually) ensures that all compilations are done with the specified flags. For setting the correct 'bittiness' of the compilation, this sometimes works better than the various other mechanisms you find - it is hard for a compilation to wriggle around it except by completely ignoring the fact you specified the C compiler to use.
Another option is to pass -fPIC directly to make in the following way:
make CFLAGS='-fPIC' CXXFLAGS='-fPIC'

Resources