Beruflich Dokumente
Kultur Dokumente
PROGRAMMING
lNo
prin!
Writing some code (1) - specifying
where code runs
lCUDA
provides
func?on
type
qualiers
(that
are
not
in
C/C++)
to
enable
programmer
to
dene
where
a
func?on
should
run
l_
_host_
_
:
species
the
code
should
run
on
the
host
CPU
(redundant
on
its
own
-
it
is
the
default)
l_
_device_
_
:
species
the
code
should
run
on
the
GPU,
and
the
func?on
can
host
-
this
is
the
access
point
to
start
mul?-threaded
codes
running
on
the
GPU
lDevice
cant
execute
code
on
the
host!
lCUDA imposes some restric?ons, such as device code is C-only (host code can be
C++), device
code
cant
be
called
recursively
Writing some code (2) - launching a
_ _global_ _ function
All calls to a global function must specify how
many threaded copies are to launch and in
what configuration.
CUDA syntax: <<< >>>
threads are grouped into thread blocks then
performance)
The thread/block/grid model
Contd..
Writing some code: _ _ global _ _
lInside
the
<<<
>>>,
need
at
least
two
arguments
(can
be
two
more,
that
have
default
values)
lCall
looks
eg.
like
my
func<<<bg,
tb>>>(arg1,
arg2)
lbg species the dimensions of the block grid and tb species the
block.
Variables are stored
lFor
code
running
on
the
GPU
(
device
and
global
),
the
memory
used
to
hold
a
variable
can
be
specied.
ldevice
:
the
variable
resides
in
the
GPUs
global
memory
and
is