embedded call to cub in static library

9 views
Skip to first unread message

rhaney

unread,
Jul 9, 2019, 7:12:35 PM7/9/19
to cub-...@googlegroups.com
Hello all,

Suppose I have a file(s) that I would like to employ CUB (cub-1.8.0) and build as a static library such that the resulting library can be ported to another directory and used. As a "toy" example I have the following cuh header file where cub-1.8.0 directory is directly above where the following (myLib.cuh) is in include/:

#ifndef __MY_LIB_H
#define __MY_LIB_H


#include <cuda.h>
#include "../cub-1.8.0/cub.h"


// The following will call cub operations
void myFunc();


#endif

The implementation of myLib.cuh (myLib.cu) is directly above the include directory and follows:

#include "./include/myLib.cuh"


void myFunc(){
 
// Make call(s) to cub
}

Is there any special command(s) that I need to compile the myLib.cu as a static library? Are the #include directive(s) too specific for good portability? I am concerned that the "#include "../cub-1.8.0/cub.h" will limit how I can use the resulting static library - e.g. if I use the resulting myLib.a library in another directory will the cub.h file be found?

Sorry if this is a dumb question, but I have never built a library calling an underlying directory.

Thank you for any help/hints anyone can give.

Robert Crovella

unread,
Jul 9, 2019, 7:25:03 PM7/9/19
to cub-users, rhaney
A library built that way would never need to reference cub.h

This isn't really specific to cub, but is a general concept when building binaries/executables/libraries.  It's not necessary for the header files that were used to build it, to be available after compilation.  You generally would not even need cub to be installed on the target machine where the library is used.

There is one exception, at least at this level of discussion.  Presumably the "interface" to your library is:

void myFunc();

The header file that contains that prototype/declaration, whatever you happen to name that include file, would need to be "available" for any code that used your library, to provide the interface.  But even that header file is only needed for compilation of the target code, it doesn't need to be on the machine where such codes are run.

Again, none of this is really specific to cub, these are general concepts for building code and libraries.

On Tuesday, July 9, 2019, 06:12:36 PM CDT, rhaney <comps...@gmail.com> wrote:


Hello all,

Suppose I have a file(s) that I would like to employ CUB (cub-1.8.0) and build as a static library such that the resulting library can be ported to another directory and used. As a "toy" example I have the following cuh header file where cub-1.8.0 directory is directly above where the following (myLib.cuh) is in include/:

#ifndef __MY_LIB_H
#define __MY_LIB_H


#include <cuda.h>
#include "../cub-1.8.0/cub.h"


// The following will call cub operations
void myFunc();


#endif

The implementation of myLib.cuh (myLib.cu) is directly above the include directory and follows:

#include "./include/myLib.cuh"


void myFunc(){
 
// Make call(s) to cub
}

Is there any special command(s) that I need to compile the myLib.cu as a static library? I am concerned that the "#include "../cub-1.8.0/cub.h" will limit how I can use the resulting static library - e.g. if I use the myLib.a library in another directory will the cub.h file be found?

Sorry if this is a dumb question, but I have never built a library calling an underlying directory.

Thank you for any help/hints anyone can give.

--
http://nvlabs.github.com/cub
---
You received this message because you are subscribed to the Google Groups "cub-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cub-users+...@googlegroups.com.
To post to this group, send email to cub-...@googlegroups.com.
Visit this group at https://groups.google.com/group/cub-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/cub-users/81098c66-8980-46d2-b21e-857250754e26%40googlegroups.com.

rhaney

unread,
Jul 9, 2019, 7:50:46 PM7/9/19
to cub-users
Thank you for the information.

Do you have a link to a simple makefile that will compile to static library?
To unsubscribe from this group and stop receiving emails from it, send an email to cub-...@googlegroups.com.

Robert Crovella

unread,
Jul 9, 2019, 8:14:42 PM7/9/19
to cub-users, rhaney
for nvcc it's very simple

nvcc -c a.cu b.cu
nvcc --lib a.o b.o -o myLib.a

This assumes you don't need device-code linking across the library interface. For the kind of interface you suggested:

void myFunc();

that is the case.

Once you have myLib.a, let's suppose you have a source file called main.cpp that uses myLib

You could do:

g++ -o test main.cpp myLib.a -L/usr/local/cuda/lib64 -lcudart

There are fully worked examples like this on stackoverflow.  Here is one that uses device-code linking:


there are many ways to skin this cat.





On Tuesday, July 9, 2019, 06:50:48 PM CDT, rhaney <comps...@gmail.com> wrote:


Thank you for the information.

Do you have a link to a simple makefile that will compile to static library?

On Tuesday, July 9, 2019 at 7:25:03 PM UTC-4, txbob wrote:
A library built that way would never need to reference cub.h

This isn't really specific to cub, but is a general concept when building binaries/executables/ libraries.  It's not necessary for the header files that were used to build it, to be available after compilation.  You generally would not even need cub to be installed on the target machine where the library is used.
To unsubscribe from this group and stop receiving emails from it, send an email to cub-users+...@googlegroups.com.

To post to this group, send email to cub-...@googlegroups.com.
Visit this group at https://groups.google.com/group/cub-users.
To view this discussion on the web visit
Reply all
Reply to author
Forward
0 new messages