Adding CUDA CUB library to a project in Visual Studio - cuda

I want to use the CUB library for a CUDA project; I'm using CUDA 11.2 on VS 2019. The CUB version integrated into CUDA 11.2 is 1.10, while I want to use BlockMergeSort which is not available in this version. Therefore, I chose to use cub 1.16.0 . The problem is, I cannot add the new cub header files in my project. I simply add .\cub-1.16.0 to Additional Include Directories in VS project properties, then use #include <cub-1.16.0/cub/block/block_merge_sort.cuh> in my source file (the path is ./cub-1.16.0/cub-1.16.0/cub).
When I do this, several errors in including headers show up, for example:
Cannot include thread_sort.cuh on #include <cub/thread/thread_sort.cuh> which is at the beginning of block_merge_sort.cuh .
I can tell why this gives an error and I can fix it manually (replacing with #include "../thread/thread_sort.cuh".) But what I don't get is the correct way of adding this library since no modifications should be required. Am I missing something when adding a header library to a VS project? And in the case of CUB, is it possible to add another version of this library when an older one already exists?

Related

How to use clangd text-highlighting with CUDA on header files

I'm running VSCodium with the clangd extension, and I'd like to have proper CUDA highlighting (e.g. __device__ and __host__ keywords are understood). I ran CMake to generate the compile_commands.json file, and it includes CUDA-specific keywords (e.g. --cuda-gpu-arch=sm_52, --cuda-path=/usr/local/cuda). However, clangd still gives me the squiggle underline on CUDA-specific keywords. It seems like if clangd is just using the clang compiler to understand the source code, then clangd should work with CUDA (given that clang was able to compile the CUDA code).
So, is there any way to get clangd to work for CUDA? And if so, how do I do it via VSCodium?
Edit: As it turns out, the CUDA code highlighting works on the directly linked files (with a .cu extension), but it does not work on one of the included header files (with a .hpp extension). How do I get the text-highlighting to work on the header file?
create a config file ".clangd" in your project directory and specify the location of CUDA headers. This works for me.
CompileFlags:
Add:
- -xc++
- --cuda-path=/path_to_cuda_installation
- --cuda-gpu-arch=sm_52
- -I/path_to_cuda_installation/include

Can I use STL in a DriverKit driver?

Can I use for example std::vector in DriverKit driver in macOs / XCode?
DriverKit has some container class like OSArray
https://developer.apple.com/documentation/driverkit/osarray?language=objc
If I create a new "DriverKit driver" project and include <vector> then I get build errors. Those error comes from including <cstring> and the error is
No member named 'strcpy' in the global namespace
No member named 'strcat' in the global namespace
As far as I can tell, you aren't supposed to. The headers you end up pulling in there aren't from the DriverKit SDK, they're the default ones that come with Xcode's compiler toolchain. They assume a normal macOS build environment, not the dext environment. The DriverKit SDK doesn't include C++ stdlib headers, and only contains some stripped-down headers for a subset of the C standard library. Hence the missing strcpy and strcat.
Linking against libc++ also fails, even the version included in the DriverKit SDK. I don't know why there is a version of that library included with the DriverKit SDK, but it's clearly not intended for being used in dexts.
There's presumably nothing in particular stopping you from including some other container library, or even directly including parts of an STL implementation. You may need to manually wire up memory allocation calls though.

Cublas error link 2019 [duplicate]

I am trying to compile a cuda program which uses cusparse library. I am getting linking error:
kernel.cu.obj : error LNK2019: unresolved external symbol _cusparseSetMatIndexBase#8 referenced in function _main
And a lot of error of same kind related to cusparse library. I have included "cusparse_v2.h".
How do i link cusparse library in visual studio 2010 during compilation?
The general instructions for linking libraries is not specific to CUDA. So you may want to learn more about using MS VS. Anyway, the steps are like this:
Make sure you have opened the project that you want to work on.
Select View...Property Pages (from the menu) A new dialog box will open up.
On the left hand side of this dialog box, select Linker to open up it's sub-menu
Under linker, select Input
Now, on the pane on the right, observe the first item which is "Additional Dependencies". I believe cudart.lib should already be present there.
Click to the right of cudart.lib You can now type in new libraries to be added. Type a space (to separate from cudart.lib) and type cusparse.lib
Now click "Apply" in the lower right corner of the dialog box.
That should be all that's needed, if your project/solution file is already set up using a cuda template. If cudart.lib is not present, or your project/solution files do not already comprehend cuda, that is a separate issue. In that case I would recommend starting over, by cloning a project from the Samples, and building your project using that as a starting point. It will then pick up all the proper directories to search as well as the cuda build rules. Since all the main cuda libraries (cudart, cublas, cufft, cusparse, etc.) are all in the same location, the same search path should pick any of them up as needed.
If you wanted to link another library, such as cublas.lib, for example, you could follow a similar sequence, replacing cusparse.lib above with cublas.lib
Note that with newer versions of CUDA (e.g. CUDA 7.5) it will be necessary to build a 64-bit project only (follow the above steps when modifying the x64 project properties.) CUDA 7.5 and beyond are dropping support for 32-bit projects.
I fixed it by following steps:
Add cuda path:
Go: "Configuration Properties->Linker->General->Additional Libary Directories" and add $(CudaToolkitLibDir) to the list.
Add cuda realtime library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cudart.lib to the list.
Add cublas library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cublas.lib to the list.
Changing platform to x64:
Go: "Configuration Properties->Platform" and set it to x64.
Run cmd.exe as administrator.
Type in and run the following two lines of command:
netsh winsock reset catalog
netsh int ip reset reset.log hit
It may say that a reboot is required, but actually that is not necessary.
Try to debug your application again, the problem should be solved.

Unresolved symbols linker error when trying to initialize cublas [duplicate]

I am trying to compile a cuda program which uses cusparse library. I am getting linking error:
kernel.cu.obj : error LNK2019: unresolved external symbol _cusparseSetMatIndexBase#8 referenced in function _main
And a lot of error of same kind related to cusparse library. I have included "cusparse_v2.h".
How do i link cusparse library in visual studio 2010 during compilation?
The general instructions for linking libraries is not specific to CUDA. So you may want to learn more about using MS VS. Anyway, the steps are like this:
Make sure you have opened the project that you want to work on.
Select View...Property Pages (from the menu) A new dialog box will open up.
On the left hand side of this dialog box, select Linker to open up it's sub-menu
Under linker, select Input
Now, on the pane on the right, observe the first item which is "Additional Dependencies". I believe cudart.lib should already be present there.
Click to the right of cudart.lib You can now type in new libraries to be added. Type a space (to separate from cudart.lib) and type cusparse.lib
Now click "Apply" in the lower right corner of the dialog box.
That should be all that's needed, if your project/solution file is already set up using a cuda template. If cudart.lib is not present, or your project/solution files do not already comprehend cuda, that is a separate issue. In that case I would recommend starting over, by cloning a project from the Samples, and building your project using that as a starting point. It will then pick up all the proper directories to search as well as the cuda build rules. Since all the main cuda libraries (cudart, cublas, cufft, cusparse, etc.) are all in the same location, the same search path should pick any of them up as needed.
If you wanted to link another library, such as cublas.lib, for example, you could follow a similar sequence, replacing cusparse.lib above with cublas.lib
Note that with newer versions of CUDA (e.g. CUDA 7.5) it will be necessary to build a 64-bit project only (follow the above steps when modifying the x64 project properties.) CUDA 7.5 and beyond are dropping support for 32-bit projects.
I fixed it by following steps:
Add cuda path:
Go: "Configuration Properties->Linker->General->Additional Libary Directories" and add $(CudaToolkitLibDir) to the list.
Add cuda realtime library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cudart.lib to the list.
Add cublas library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cublas.lib to the list.
Changing platform to x64:
Go: "Configuration Properties->Platform" and set it to x64.
Run cmd.exe as administrator.
Type in and run the following two lines of command:
netsh winsock reset catalog
netsh int ip reset reset.log hit
It may say that a reboot is required, but actually that is not necessary.
Try to debug your application again, the problem should be solved.

CUDA5 Examples: Has anyone translated some cutil definitions to CUDA5?

Has anyone started to work with the CUDA5 SDK?
I have an old project that uses some cutil functions, but they've been abandoned in the new one.
The solution was that most functions can be translated from cutil*/cut* to a similar named sdk* equivalent from the helper*.h headers...
As an example:
cutStartTimer becomes sdkCreateTimer
Just that simple...
Has anyone started to work with the CUDA5 SDK?
Probably.
Has anyone translated some cutil definitions to CUDA5?
Maybe. But why not just use the new header files intended to replace it? Quoted from the Beta release notes:
Prior to CUDA 5.0, CUDA Sample projects referenced a utility library
with header and source files called cutil. This has been removed with
the CUDA Samples in CUDA 5.0, and replaced with header files found
in CUDA Samples\v5.0\C\common\inc
helper_cuda.h, helper_cuda_gl.h, helper_cuda_drvapi.h, helper_functions.h,
helper_image.h, helper_math.h, helper_string.h, and helper_timer.h
These files provide utility functions for CUDA device initialization,
CUDA error checking, string parsing, image file loading and saving, and
timing functions. The CUDA Samples projects no longer have references
and dependencies to cutil, and will now use these helper functions
going forward.