Compiler does not support #pragma once - thrust

I have a compiler (PGI) that does not support
#pragma once
but the library (thrust) I would like to include uses them.
Is there a workaround for this problem?

You could use guardonce to convert the #pragma once statements to standard #ifndef ... include guards.
The following worked for me:
cd /tmp
git clone https://github.com/thrust/thrust.git
git clone https://github.com/cgmb/guardonce.git
cd guardonce
git checkout v2.0.0
python -m guardonce.once2guard -r "/tmp/thrust/thrust/"
This creates the include guards in every thrust header file:
git diff /tmp/thrust
--- a/thrust/adjacent_difference.h
+++ b/thrust/adjacent_difference.h
## -19,7 +19,8 ##
* \brief Compute difference between consecutive elements of a range
*/
-#pragma once
+#ifndef ADJACENT_DIFFERENCE_H
+#define ADJACENT_DIFFERENCE_H
. . .

Well, macros (and therefore #pragma) are handled by the preprocessor (cpp, not to be mistaken with c++ extension), so theoretically you could try using a preprocessor that supports #pragma, and then build the resulting code with your compiler.

Related

How to link cusparse using CMakeLists.txt

How can I add the cusparse library from CUDA in a CMakeLists.txt-file, such that the nvcc compiler includes it automatically with -lcusparse? I already added the line
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-lcusparse)
in CMakeLists.txt with no success. It looks like I'm missing something, because Nsight throws the error
undefined reference to 'cusparseDestroyMatDescr'.
Although when I exclude this line where cusparseDestroyMatDescr is called via commenting it, the Nsight project builds with no error, even with these three lines of code included
cusparseStatus_t status;
cusparseHandle_t handle=0;
cusparseMatDescr_t descr=0;
So it looks like it knows what cusparseStatus_t and so on is, but it does not know what cusparseDestroyMatDescr is.
What do I miss?
The correct way in CMake to link a library is using
target_link_libraries( target library ).
If you use FindCUDA to locate the CUDA installation, the variable CUDA_cusparse_LIBRARY will be defined. Thus, all you need to do is
target_link_libraries( target ${CUDA_cusparse_LIBRARY} )
I recommend to use the CMake CUDAToolkit package, which is available with CMake 3.17 and newer:
find_package(CUDAToolkit REQUIRED)
...
target_link_libraries(target CUDA::cusparse)

Bitbake append file to reconfigure kernel

I'm trying to reconfigure some .config variables to generate a modified kernel with wifi support enabled. The native layer/recipe for the kernel is located in this directory:
meta-layer/recipes-kernel/linux/linux-yocto_3.19.bb
First I reconfigure the native kernel to add wifi support (for example, adding CONFIG_WLAN=y):
$ bitbake linux-yocto -c menuconfig
After that, I generate a "fragment.cfg" file:
$ bitbake linux-yocto -c diffconfig
I have created this directory into my custom-layer:
custom-layer/recipes-kernel/linux/linux-yocto/
I have copied the "fragment.cfg file into this directory:
$ cp fragment.cfg custom-layer/recipes-kernel/linux/linux-yocto/
I have created an append file to customize the native kernel recipe:
custom-layer/recipes-kernel/linux/linux-yocto_3.19.bbappend
This is the content of this append file:
FILESEXTRAPATHS_prepend:="${THISDIR}/${PN}:"
SRC_URI += "file://fragment.cfg"
After that I execute the kernel compilation:
$ bitbake linux-yocto -c compile -f
After this command, "fragment.cfg" file can be found into this working directory:
tmp/work/platform/linux-yocto/3.19-r0
However none of the expected variables is active on the .config file (for example, CONFIG_WLAN is not set).
How can I debug this issue? What is supposed I'm doing wrong?
When adding this configuration you want to use append in your statement such as:
SRC_URI_append = "file://fragment.cfg"
After analyzing different links and solutions proposed on different resources, I finally found the link https://community.freescale.com/thread/376369 pointing to a nasty but working patch, consisting in adding this function at the end of append file:
do_configure_append() {
cat ${WORKDIR}/*.cfg >> ${B}/.config
}
It works, but I expected Yocto managing all this stuff. It would be nice to know what is wrong with the proposed solution. Thank you in advance!
If your recipe is based on kernel.bbclass then fragments will not work. You need to inherit kernel-yocto.bbclass
You can also use merge_config.sh scripts which is present in kernel sources. I did something like this:
do_configure_append () {
${S}/scripts/kconfig/merge_config.sh -m -O ${WORKDIR}/build ${WORKDIR}/build/.config ${WORKDIR}/*.cfg
}
Well, unfortunately, not a real answer... As I haven't been digging deep enough.
This was working alright for me on a Daisy-based build, however, when updating the build system to Jethro or Krogoth, I get the same issue as you.
Issue:
When adding a fragment like
custom-layer/recipes-kernel/linux/linux-yocto/cdc-ether.cfg
The configure step of the linux-yocto build won't find it. However, if you move it to:
custom-layer/recipes-kernel/linux/linux-yocto/${MACHINE}/cdc-ether.cfg
it'll work as expected. And it's a sligthly less hackish way of getting it to work.
If anyone comes by, this is working on jethro and sumo:
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI_append = " \
file://fragment.cfg \
"
FILESEXTRAPATHS documentation says:
Extends the search path the OpenEmbedded build system uses when looking for files and patches as it processes recipes and append files. The directories BitBake uses when it processes recipes are defined by the FILESPATH variable, and can be extended using FILESEXTRAPATHS.

CMake: how to add cuda to existing project

I have a project that builds a library and I want to add some cuda support to it.
The structure is:
|Basedir
|_subdir1
|_subdir2
The basic structure of the CMakeLists.txt files: (subdir2 is not important).
in Basedir:
cmake_minimum_required(VERSION 2.6)
PROJECT(myproject)
find_package(CUDA)
INCLUDE_DIRECTORIES(${MYPROJECT_SOURCE_DIR})
ADD_SUBDIRECTORY(subdir1)
ADD_SUBDIRECTORY(subdir2)
in subdir1:
ADD_LIBRARY(mylib shared
file1.cpp
file2.cpp
file3.cpp
)
INSTALL(
TARGETS mylib
DESTINATION lib
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
FILE(GLOB_RECURSE HEADERS RELATIVE ${MYPROJECT_SOURCE_DIR}/myproject *.h)
FOREACH(HEADER ${HEADERS})
STRING(REGEX MATCH "(.*)[/\\]" DIR ${HEADER})
INSTALL(FILES ${HEADER} DESTINATION include/myproject/${DIR})
ENDFOREACH(HEADER)
I actually don't really know how to put the cuda-support into it. I want to replace file2.cpp with file2.cu and I did that, but it didn't build the .cu file, only the cpp files.
Do I have to add CUDA_ADD_EXECUTABLE() to include any cuda-files? How will I then link it to the other files?
I tried adding the following to the CMakeLists.txt in subdir1:
CUDA_ADD_EXECUTABLE(cuda file2.cu OPTIONS -arch sm_20)
That will compile the file but build an executable cuda. How do I link it to mylib?
Just with?:
TARGET_LINK_LIBRARIES(cuda mylib)
I have to admit that I'm not experienced in cmake, but I guess you figured that.
You can use CUDA_ADD_LIBRARY for mylib project. It works as CUDA_ADD_EXECUTABLE but for libraries.
CUDA_ADD_LIBRARY(mylib SHARED
file1.cpp
file2.cu
file3.cpp
OPTIONS -arch sm_20
)
TARGET_LINK_LIBRARIES(mylib ${CUDA_LIBRARIES})

Is it possible to (easily?) re-write the paths within a Mercurial Queue patch?

I've got some MQ patches with work implemented in file path project/feature_a, but I need to move these changes to project/feature_b. Is there an easy way to do this?
The only way is to modify the patch files directly with a tool or an editor.
You must (of course) do this while the patches are unapplied, so begin with
$ hg qpop -a
Then edit the patches in .hg/patches using either an editor of your choice or perhaps by using filterdiff from patchutils. Running
$ filterdiff --strip 3 \
--addoldprefix a/project/feature_b/ \
--addnewprefix b/project/feature_b/ your-patch
might do the trick by stripping off the old a/project/feature_b prefixes before adding new ones.

Amending a complex Makefile for installing a library used in one module of an OCaml package

I need to add the csv module in one module compute.ml of an OCAML package.(see discussion ocaml hash from mysql)
Do you know of a simple way to amend the makefile (it is a complex document in my case and I don't think that I can fully rewrite it or switch to ocamlfind install) to enable a compilation without "Unbound value Csv.load" error messages?
ie can I include a new library inside an existing stable Ocaml package?
modified module : compute.ml,
modification;
let data = Csv.load ("foo.csv")
....
error message during compilation :
camlp5r ../wserver/pa_macro5.cmo -DUNIX -o compute.ppo compute.ml
ocamlopt.opt -warn-error A -I ../wserver -I ../sally -I +camlp5 -c -impl compute.ppo
File "compute.ml", line 110, characters 13-21:
Error: Unbound value Csv.load
Thanks for help
You have to tell ocamlopt where to look for csv.cm{i,x} files with the appropriate -I option, like the ones you already have at the end of your command line.
If the library lies in a subdirectory of OCaml's standard library (as given by ocamlc -where), you can use
-I +csv_dir, as is done for camlp5 in your example. Otherwise, you'll have to provide the full path.
Note that this is not the only modification that you'll have to do: you'll also have to add csv.cmx (or .cmxa) on the command line that perform the final link of your application/library.