/extra/cuda/demos/hello-world/hello-world.factor

http://github.com/abeaumont/factor · Factor · 26 lines · 19 code · 5 blank · 2 comment · 0 complexity · 40e5af34e21facae9bf8dc33038b4041 MD5 · raw file

  1. ! Copyright (C) 2010 Doug Coleman.
  2. ! See http://factorcode.org/license.txt for BSD license.
  3. USING: accessors alien.c-types alien.strings byte-arrays cuda
  4. cuda.contexts cuda.devices cuda.libraries cuda.memory cuda.syntax
  5. destructors io io.encodings.string io.encodings.utf8 kernel locals
  6. math math.parser namespaces sequences strings ;
  7. IN: cuda.demos.hello-world
  8. CUDA-LIBRARY: hello cuda32 vocab:cuda/demos/hello-world/hello.ptx
  9. CUDA-FUNCTION: helloWorld ( char* string-ptr ) ;
  10. : cuda-hello-world ( -- )
  11. init-cuda
  12. [
  13. [
  14. context-device number>string
  15. "CUDA device " ": " surround write
  16. "Hello World!" >byte-array [ - ] map-index host>device &cuda-free
  17. [ { 2 1 } { 6 1 1 } <grid> helloWorld ]
  18. [ 12 device>host >string print ] bi
  19. ] with-destructors
  20. ] with-each-cuda-device ;
  21. MAIN: cuda-hello-world