Can I use STL in a DriverKit driver? - stl

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.

Related

Adding CUDA CUB library to a project in Visual Studio

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?

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.

Tcl version change issue from 8.4 to 8.5.12

I have a problem with changing tcl version from 8.4 to 8.5.12 on RHEL machine. Our product uses TclDevKit components like Tcldom, Tclxml, etc. Also we are using Incr Tcl (Itcl). I am trying to create pkgIndex.tcl file in Itcl in order to find Itcl when that package is required as follown:
package ifneeded Itcl 3.4 [list load [file join $dir "libitcl-O.a"] Itcl ]
but when I use
package require Itcl
Getting report: couldn't load file "/somepath/itcl/lib/libitcl-O.a": /somepath/lib/libitcl-O.a: invalid ELF header
It seems I can't load files with .a extention, but the same is done with previous version of tcl (8.4) and it works fine. I googled a lot, read a lot of documentation, but it doesn't help to go further.
Please help.
Thanks in advance
Libraries come in two general sorts, static libraries and shared libraries. On Linux, static libraries have the extension .a by default, and shared libraries have the extension .so (plus optionally some numbers to indicate the version). Only shared libraries will work with Tcl's load command and even then they have to be designed to work that way (with an appropriate Foobar_Init function, as documented).
When dealing with stub-exporting extensions (fairly rare) or Tcl and Tk themselves, the linking is done in two parts. There's a stub library, normally called somethingstub.a, and there's a main shared library. The main shared library contains the implementation of the code; all that is in the stub library is an ABI/API adaptor so that you can avoid binding your code to an explicit version of the implementation library. By building an extension stub-enabled and linking against the stub library, you gain the ability to have your extension loaded into future versions of Tcl/Tk without any recompilation or relinking steps at all. (You also become able to put the extension inside a starkit for deployment, as those use a rather unusual way of managing shared libraries that the stub mechanism conceals from you.)

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.