<commit_before>! Copyright (C) 2010 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.data alien.destructors assocs
byte-arrays cuda cuda.ffi destructors fry io.encodings.string
io.encodings.utf8 kernel locals math namespaces sequences
strings ;
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 )
    c:heap-size * cuda-malloc ; inline

: cuda-free ( ptr -- )
    cuMemFree cuda-error ; inline

DESTRUCTOR: cuda-free

: memcpy-device>device ( dest-ptr src-ptr count -- )
    cuMemcpyDtoD cuda-error ; inline

: memcpy-device>array ( dest-array dest-index src-ptr count -- )
    cuMemcpyDtoA cuda-error ; inline

: memcpy-array>device ( dest-ptr src-array src-index count -- )
    cuMemcpyAtoD cuda-error ; inline

: memcpy-array>host ( dest-ptr src-array src-index count -- )
    cuMemcpyAtoH cuda-error ; inline

: memcpy-host>array ( dest-array dest-index src-ptr count -- )
    cuMemcpyHtoA cuda-error ; inline

: memcpy-array>array ( dest-array dest-index src-array src-ptr count -- )
    cuMemcpyAtoA cuda-error ; inline

: memcpy-host>device ( dest-ptr src-ptr count -- )
    cuMemcpyHtoD cuda-error ; inline

: memcpy-device>host ( dest-ptr src-ptr count -- )
    cuMemcpyDtoH cuda-error ; inline

: host>device ( data -- ptr )
    [ >c-ptr ] [ byte-length ] bi
    [ nip cuda-malloc dup ] [ memcpy-host>device ] 2bi ; inline

: device>host ( ptr len -- byte-array )
    [ nip <byte-array> dup ] [ memcpy-device>host ] 2bi ; inline
<commit_msg>cuda.memory: use binary-object.<commit_after>! Copyright (C) 2010 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.data alien.destructors assocs
byte-arrays cuda cuda.ffi destructors fry io.encodings.string
io.encodings.utf8 kernel locals math namespaces sequences
strings ;
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 )
    c:heap-size * cuda-malloc ; inline

: cuda-free ( ptr -- )
    cuMemFree cuda-error ; inline

DESTRUCTOR: cuda-free

: memcpy-device>device ( dest-ptr src-ptr count -- )
    cuMemcpyDtoD cuda-error ; inline

: memcpy-device>array ( dest-array dest-index src-ptr count -- )
    cuMemcpyDtoA cuda-error ; inline

: memcpy-array>device ( dest-ptr src-array src-index count -- )
    cuMemcpyAtoD cuda-error ; inline

: memcpy-array>host ( dest-ptr src-array src-index count -- )
    cuMemcpyAtoH cuda-error ; inline

: memcpy-host>array ( dest-array dest-index src-ptr count -- )
    cuMemcpyHtoA cuda-error ; inline

: memcpy-array>array ( dest-array dest-index src-array src-ptr count -- )
    cuMemcpyAtoA cuda-error ; inline

: memcpy-host>device ( dest-ptr src-ptr count -- )
    cuMemcpyHtoD cuda-error ; inline

: memcpy-device>host ( dest-ptr src-ptr count -- )
    cuMemcpyDtoH cuda-error ; inline

: host>device ( data -- ptr )
    binary-object
    [ nip cuda-malloc dup ] [ memcpy-host>device ] 2bi ; inline

: device>host ( ptr len -- byte-array )
    [ nip <byte-array> dup ] [ memcpy-device>host ] 2bi ; inline

{'fraction_non_alphanumeric': 0.12310491206791996, 'fraction_numerical': 0.004244996967859308, 'mean_word_length': 3.098136645962733, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5193171', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1161, 'n_words': 282}