Skip to content

Commit d57ca44

Browse files
committed
Enable CUDA support.
This commit also reintroduces nvcore Library.h and Library.cpp files required by nvtt/cuda/CudaUtils.cpp Ref: castano#230 castano@81336cc Signed-off-by: Elvis Dowson <[email protected]>
1 parent 662d223 commit d57ca44

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ SUBDIRS(bc7)
5252
#ENDIF(CG_FOUND)
5353

5454
# CUDA
55-
#FIND_PACKAGE(CUDA)
55+
FIND_PACKAGE(CUDA)
5656
IF(CUDA_FOUND)
5757
IF(MINGW)
5858
MESSAGE(STATUS "Looking for CUDA - not supported on MinGW")

src/nvcore/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SET(CORE_SRCS
1010
DefsVcWin32.h
1111
FileSystem.h FileSystem.cpp
1212
ForEach.h
13+
Library.h Library.cpp
1314
Memory.h Memory.cpp
1415
Ptr.h
1516
RefCounted.h

src/nvcore/Library.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "Library.h"
2+
#include "Debug.h"
3+
4+
#if NV_OS_WIN32
5+
#define WIN32_LEAN_AND_MEAN
6+
#define VC_EXTRALEAN
7+
#include <windows.h>
8+
#elif NV_OS_XBOX
9+
#include <Xtl.h>
10+
#else
11+
#include <dlfcn.h>
12+
#endif
13+
14+
15+
16+
void * nvLoadLibrary(const char * name)
17+
{
18+
#if NV_OS_WIN32
19+
return (void *)LoadLibraryExA( name, NULL, 0 );
20+
#elif NV_OS_XBOX
21+
return (void *)LoadLibraryA( name );
22+
#else
23+
return dlopen(name, RTLD_LAZY);
24+
#endif
25+
}
26+
27+
void nvUnloadLibrary(void * handle)
28+
{
29+
nvDebugCheck(handle != NULL);
30+
#if NV_OS_WIN32 || NV_OS_XBOX
31+
FreeLibrary((HMODULE)handle);
32+
#else
33+
dlclose(handle);
34+
#endif
35+
}
36+
37+
void * nvBindSymbol(void * handle, const char * symbol)
38+
{
39+
#if NV_OS_WIN32 || NV_OS_XBOX
40+
return (void *)GetProcAddress((HMODULE)handle, symbol);
41+
#else
42+
return (void *)dlsym(handle, symbol);
43+
#endif
44+
}

src/nvcore/Library.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// This code is in the public domain -- [email protected]
2+
3+
#pragma once
4+
#ifndef NV_CORE_LIBRARY_H
5+
#define NV_CORE_LIBRARY_H
6+
7+
#include "nvcore.h"
8+
9+
#if NV_OS_WIN32
10+
#define LIBRARY_NAME(name) #name ".dll"
11+
#elif NV_OS_DARWIN
12+
#define NV_LIBRARY_NAME(name) "lib" #name ".dylib"
13+
#else
14+
#define NV_LIBRARY_NAME(name) "lib" #name ".so"
15+
#endif
16+
17+
NVCORE_API void * nvLoadLibrary(const char * name);
18+
NVCORE_API void nvUnloadLibrary(void * lib);
19+
NVCORE_API void * nvBindSymbol(void * lib, const char * symbol);
20+
21+
class NVCORE_CLASS Library
22+
{
23+
public:
24+
Library(const char * name)
25+
{
26+
handle = nvLoadLibrary(name);
27+
}
28+
~Library()
29+
{
30+
if (isValid())
31+
{
32+
nvUnloadLibrary(handle);
33+
}
34+
}
35+
36+
bool isValid() const
37+
{
38+
return handle != NULL;
39+
}
40+
41+
void * bindSymbol(const char * symbol)
42+
{
43+
return nvBindSymbol(handle, symbol);
44+
}
45+
46+
private:
47+
void * handle;
48+
};
49+
50+
51+
#endif // NV_CORE_LIBRARY_H

src/nvtt/cuda/CudaUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// OTHER DEALINGS IN THE SOFTWARE.
2424

2525
#include "nvcore/Debug.h"
26+
#include "nvcore/Library.h"
2627
#include "CudaUtils.h"
2728

2829
#if defined HAVE_CUDA

0 commit comments

Comments
 (0)