factor/extra/cuda/memory/memory.factor

52 lines
1.6 KiB
Factor
Raw Normal View History

! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2010-05-03 21:18:10 -04:00
USING: accessors alien alien.data alien.destructors assocs
2010-05-20 17:32:35 -04:00
byte-arrays cuda cuda.ffi destructors fry io.encodings.string
io.encodings.utf8 kernel locals math namespaces sequences
strings ;
2010-05-03 21:18:10 -04:00
QUALIFIED-WITH: alien.c-types c
IN: cuda.memory
: cuda-malloc ( n -- ptr )
[ { CUdeviceptr } ] dip
'[ _ cuMemAlloc cuda-error ] with-out-parameters ; inline
: cuda-malloc-type ( n type -- ptr )
2010-05-05 20:38:59 -04:00
c:heap-size * cuda-malloc ; inline
2010-05-03 21:18:10 -04:00
: cuda-free ( ptr -- )
cuMemFree cuda-error ; inline
2010-05-03 21:18:10 -04:00
DESTRUCTOR: cuda-free
: memcpy-device>device ( dest-ptr src-ptr count -- )
2010-05-03 21:18:10 -04:00
cuMemcpyDtoD cuda-error ; inline
: memcpy-device>array ( dest-array dest-index src-ptr count -- )
2010-05-03 21:18:10 -04:00
cuMemcpyDtoA cuda-error ; inline
: memcpy-array>device ( dest-ptr src-array src-index count -- )
2010-05-03 21:18:10 -04:00
cuMemcpyAtoD cuda-error ; inline
: memcpy-array>host ( dest-ptr src-array src-index count -- )
2010-05-03 21:18:10 -04:00
cuMemcpyAtoH cuda-error ; inline
: memcpy-host>array ( dest-array dest-index src-ptr count -- )
2010-05-03 21:18:10 -04:00
cuMemcpyHtoA cuda-error ; inline
: memcpy-array>array ( dest-array dest-index src-array src-ptr count -- )
2010-05-03 21:18:10 -04:00
cuMemcpyAtoA cuda-error ; inline
2010-05-03 21:18:10 -04:00
: memcpy-host>device ( dest-ptr src-ptr count -- )
cuMemcpyHtoD cuda-error ; inline
2010-05-03 21:18:10 -04:00
: memcpy-device>host ( dest-ptr src-ptr count -- )
cuMemcpyDtoH cuda-error ; inline
2010-05-03 21:18:10 -04:00
: host>device ( data -- ptr )
2014-11-20 21:41:19 -05:00
binary-object
2010-05-03 21:18:10 -04:00
[ nip cuda-malloc dup ] [ memcpy-host>device ] 2bi ; inline
2010-05-03 21:18:10 -04:00
: device>host ( ptr len -- byte-array )
[ nip <byte-array> dup ] [ memcpy-device>host ] 2bi ; inline