]> gitweb.factorcode.org Git - factor.git/blob - extra/cuda/memory/memory.factor
factor: trim using lists
[factor.git] / extra / cuda / memory / memory.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types alien.data alien.destructors
4 byte-arrays cuda cuda.ffi kernel math ;
5 QUALIFIED-WITH: alien.c-types c
6 IN: cuda.memory
7
8 : cuda-malloc ( n -- ptr )
9     [ { CUdeviceptr } ] dip
10     '[ _ cuMemAlloc cuda-error ] with-out-parameters ; inline
11
12 : cuda-malloc-type ( n type -- ptr )
13     c:heap-size * cuda-malloc ; inline
14
15 : cuda-free ( ptr -- )
16     cuMemFree cuda-error ; inline
17
18 DESTRUCTOR: cuda-free
19
20 : memcpy-device>device ( dest-ptr src-ptr count -- )
21     cuMemcpyDtoD cuda-error ; inline
22
23 : memcpy-device>array ( dest-array dest-index src-ptr count -- )
24     cuMemcpyDtoA cuda-error ; inline
25
26 : memcpy-array>device ( dest-ptr src-array src-index count -- )
27     cuMemcpyAtoD cuda-error ; inline
28
29 : memcpy-array>host ( dest-ptr src-array src-index count -- )
30     cuMemcpyAtoH cuda-error ; inline
31
32 : memcpy-host>array ( dest-array dest-index src-ptr count -- )
33     cuMemcpyHtoA cuda-error ; inline
34
35 : memcpy-array>array ( dest-array dest-index src-array src-ptr count -- )
36     cuMemcpyAtoA cuda-error ; inline
37
38 : memcpy-host>device ( dest-ptr src-ptr count -- )
39     cuMemcpyHtoD cuda-error ; inline
40
41 : memcpy-device>host ( dest-ptr src-ptr count -- )
42     cuMemcpyDtoH cuda-error ; inline
43
44 : host>device ( data -- ptr )
45     binary-object
46     [ nip cuda-malloc dup ] [ memcpy-host>device ] 2bi ; inline
47
48 : device>host ( ptr len -- byte-array )
49     [ nip <byte-array> dup ] [ memcpy-device>host ] 2bi ; inline