Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
conda
docs
Commits
1b4259f7
Commit
1b4259f7
authored
Jan 27, 2021
by
Paul McCarthy
🚵
Browse files
ENH: example hybrid CPU/GPU project
parent
778bd66b
Changes
5
Hide whitespace changes
Inline
Side-by-side
examples/cuda/example_cuda_project/Makefile
0 → 100644
View file @
1b4259f7
include
${FSLCONFDIR}/default.mk
PROJNAME
=
example_cuda_project
# All shared library dependencies required
# for linking CUDA libraries and executables
# must be added as CUDALIBS
CUDALIBS
=
-lcudart
-lcuda
# This makefile is constructed such that:
# - "make" will compile only CPU binaries
# - "make gpu=1" will compile both CPU and GPU binaries
# - "make cpu=0 gpu=1" will compile only GPU binaries
SOFILES
=
XFILES
=
cpu
?=
1
gpu
?=
0
ifeq
($(cpu), 1)
XFILES
+=
example_non_cuda_exe
endif
ifeq
($(gpu), 1)
XFILES
+=
example_cuda_exe
SOFILES
+=
libfsl-example_cuda_lib.so
endif
all
:
${XFILES} ${SOFILES}
libfsl-example_cuda_lib.so
:
example_cuda_lib.cu
${NVCC}
${NVCCFLAGS}
-shared
-o
$@
$^
${NVCCLDFLAGS}
example_cuda_exe
:
example_cuda_exe.cpp libfsl-example_cuda_lib.so
${NVCC}
${NVCCFLAGS}
-o
$@
$<
-lfsl-example_cuda_lib
${NVCCLDFLAGS}
example_non_cuda_exe
:
example_non_cuda_exe.cpp
${CXX}
${CXXFLAGS}
-o
$@
$<
${LDFLAGS}
examples/cuda/example_cuda_project/example_cuda_exe.cpp
0 → 100644
View file @
1b4259f7
#include <iostream>
#include "example_cuda_lib.h"
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
std
::
cout
<<
"Usage: example_cuda_exe name"
<<
std
::
endl
;
return
1
;
}
helloworld
(
argv
[
1
]);
return
0
;
}
examples/cuda/example_cuda_project/example_cuda_lib.cu
0 → 100644
View file @
1b4259f7
#include <string>
#include <iostream>
#include "example_cuda_lib.h"
void
helloworld
(
std
::
string
s
)
{
int
driverVersion
;
int
runtimeVersion
;
char
*
memory
;
std
::
cout
<<
"Hello, "
<<
s
<<
std
::
endl
;
if
(
cudaDriverGetVersion
(
&
driverVersion
)
!=
0
)
{
std
::
cout
<<
"Error querying CUDA driver version!"
<<
std
::
endl
;
}
std
::
cout
<<
"CUDA driver version: "
<<
driverVersion
<<
std
::
endl
;
if
(
cudaRuntimeGetVersion
(
&
runtimeVersion
)
!=
0
)
{
std
::
cout
<<
"Error querying CUDA runtime version!"
<<
std
::
endl
;
return
;
}
std
::
cout
<<
"CUDA runtime version: "
<<
runtimeVersion
<<
std
::
endl
;
if
(
cudaMalloc
(
&
memory
,
1024
)
!=
0
)
{
std
::
cout
<<
"Error allocating memory!"
<<
std
::
endl
;
}
if
(
cudaFree
(
memory
)
!=
0
)
{
std
::
cout
<<
"Error freeing memory!"
<<
std
::
endl
;
}
std
::
cout
<<
"Successfully allocated memory on GPU"
<<
std
::
endl
;
}
examples/cuda/example_cuda_project/example_cuda_lib.h
0 → 100644
View file @
1b4259f7
#ifndef EXAMPLE_CPP_LIB_H
#define EXAMPLE_CPP_LIB_H
#include <string>
#include <iostream>
void
helloworld
(
std
::
string
s
);
#endif
examples/cuda/example_cuda_project/example_non_cuda_exe.cpp
0 → 100644
View file @
1b4259f7
#include <iostream>
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
std
::
cout
<<
"Usage: example_non_cuda_exe name"
<<
std
::
endl
;
return
1
;
}
std
::
cout
<<
"Hello, "
<<
argv
[
1
]
<<
std
::
endl
;
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment