/opencl/c/5-6.rkt

http://github.com/jeapostrophe/opencl · Racket · 114 lines · 107 code · 3 blank · 4 comment · 6 complexity · c4b7c16fc637508a32992adcb67d2da3 MD5 · raw file

  1. #lang at-exp racket/base
  2. (require ffi/unsafe
  3. (except-in racket/contract ->)
  4. (prefix-in c: racket/contract)
  5. scribble/srcdoc
  6. "include/cl.rkt"
  7. "lib.rkt"
  8. "syntax.rkt"
  9. "types.rkt")
  10. (require/doc racket/base
  11. scribble/manual
  12. (for-label "types.rkt"))
  13. ;;;;
  14. (define-opencl clEnqueueNDRangeKernel
  15. (_fun [command_queue : _cl_command_queue]
  16. [kernel : _cl_kernel]
  17. [work_dim : _cl_uint]
  18. ; XXX Must be NULL right now
  19. [global_work_offset : _pointer = #f]
  20. [global_work_size : (_vector i _size_t)] ; len = work_dim
  21. [local_work_size : (_vector i _size_t)]
  22. [num_events_in_wait_list : _cl_uint = (vector-length event_wait_list)]
  23. [event_wait_list : (_vector i _cl_event)]
  24. [event : (_ptr o _cl_event/null)]
  25. -> [status : _cl_int]
  26. ->
  27. (cond
  28. [(= status CL_SUCCESS)
  29. event]
  30. [(= status CL_INVALID_PROGRAM_EXECUTABLE)
  31. (error 'clEnqueueNDRangeKernel "there is no successfully built program executable available for device associated with command_queue.")]
  32. [(= status CL_INVALID_COMMAND_QUEUE)
  33. (error 'clEnqueueNDRangeKernel "command_queue is not a valid command-queue")]
  34. [(= status CL_INVALID_KERNEL)
  35. (error 'clEnqueueNDRangeKernel "kernel is not a valid kernel object")]
  36. [(= status CL_INVALID_CONTEXT)
  37. (error 'clEnqueueNDRangeKernel "context associated with command_queue and kernel is not the same or if the context associated with command_queue and events in event_wait_list are not the same.")]
  38. [(= status CL_INVALID_KERNEL_ARGS)
  39. (error 'clEnqueueNDRangeKernel "the kernel argument values have not been specified")]
  40. [(= status CL_INVALID_WORK_DIMENSION)
  41. (error 'clEnqueueNDRangeKernel "work_dim is not a valid value")]
  42. [(= status CL_INVALID_GLOBAL_WORK_SIZE)
  43. (error 'clEnqueueNDRangeKernel "global_work_size is NULL, or if any of the values specified in global_work_size[0], ... global_work_size[work_dim – 1] are 0 or exceed the range given by the sizeof(size_t) for the device on which the kernel execution will be enqueued.")]
  44. [(= status CL_INVALID_WORK_GROUP_SIZE)
  45. (error 'clEnqueueNDRangeKernel "local_work_size is specified and number of work- items specified by global_work_size is not evenly divisible by size of work-group given by local_work_size or does not match the work-group size specified for kernel using the __attribute__((reqd_work_group_size(X, Y, Z))) qualifier in program source. OR local_work_size is specified and the total number of work-items in the work-group computed as local_work_size[0] * ... local_work_size[work_dim – 1] is greater than the value specified by CL_DEVICE_MAX_WORK_GROUP_SIZE in table 4.3. OR local_work_size is NULL and the __attribute__((reqd_work_group_size(X, Y, Z))) qualifier is used to declare the work-group size for kernel in the program source.")]
  46. [(= status CL_INVALID_WORK_ITEM_SIZE)
  47. (error 'clEnqueueNDRangeKernel "the number of work-items specified in any of local_work_size[0], ... local_work_size[work_dim – 1] is greater than the corresponding values specified by CL_DEVICE_MAX_WORK_ITEM_SIZES[0], .... CL_DEVICE_MAX_WORK_ITEM_SIZES[work_dim – 1].")]
  48. [(= status CL_INVALID_GLOBAL_OFFSET)
  49. (error 'clEnqueueNDRangeKernel "global_work_offset is not NULL")]
  50. [(= status CL_OUT_OF_RESOURCES)
  51. (error 'clEnqueueNDRangeKernel "there is a failure to queue the execution instance of kernel on the command-queue because of insufficient resources needed to execute the kernel")]
  52. [(= status CL_MEM_OBJECT_ALLOCATION_FAILURE)
  53. (error 'clEnqueueNDRangeKernel "there is a failure to allocate memory for data store associated with image or buffer objects specified as arguments to kernel")]
  54. [(= status CL_INVALID_EVENT_WAIT_LIST)
  55. (error 'clEnqueueNDRangeKernel "event_wait_list is NULL and num_events_in_wait_list > 0 or event_wait_list is not NULL and num_events_in_wait_list is 0 or if event objects in event_wait_list are not valid events")]
  56. [(= status CL_OUT_OF_HOST_MEMORY)
  57. (error 'clEnqueueNDRangeKernel "there is a failure to allocate resources required by the OpenCL implementation on the host")]
  58. [else
  59. (error 'clEnqueueNDRangeKernel "Invalid error code: ~e" status)])))
  60. (provide/doc
  61. [proc-doc/names
  62. clEnqueueNDRangeKernel
  63. (c:-> _cl_command_queue/c _cl_kernel/c
  64. (and/c _cl_uint/c (between/c 1 3))
  65. (vectorof _size_t/c)
  66. (vectorof _size_t/c)
  67. (vectorof _cl_event/c)
  68. _cl_event/c)
  69. (cq kernel dim global-size local-size wait-list)
  70. @{}])
  71. ;;;; clEnqueueTask
  72. (define-opencl clEnqueueTask
  73. (_fun [command_queue : _cl_command_queue]
  74. [kernel : _cl_kernel]
  75. [num_events_in_wait_list : _cl_uint = (vector-length event_wait_list)]
  76. [event_wait_list : (_vector i _cl_event)]
  77. [event : (_ptr o _cl_event/null)]
  78. -> [status : _cl_int]
  79. ->
  80. (cond
  81. [(= status CL_SUCCESS)
  82. event]
  83. [(= status CL_INVALID_PROGRAM_EXECUTABLE)
  84. (error 'clEnqueueTask "there is no successfully built program executable available for device associated with command_queue.")]
  85. [(= status CL_INVALID_COMMAND_QUEUE)
  86. (error 'clEnqueueTask "command_queue is not a valid command-queue")]
  87. [(= status CL_INVALID_KERNEL)
  88. (error 'clEnqueueTask "kernel is not a valid kernel object")]
  89. [(= status CL_INVALID_CONTEXT)
  90. (error 'clEnqueueTask "context associated with command_queue and kernel is not the same or if the context associated with command_queue and events in event_wait_list are not the same.")]
  91. [(= status CL_INVALID_KERNEL_ARGS)
  92. (error 'clEnqueueTask "the kernel argument values have not been specified")]
  93. [(= status CL_INVALID_WORK_GROUP_SIZE)
  94. (error 'clEnqueueTask "work-group size is specified for kernel using ... qualifier in program source and is not (1, 1, 1)")]
  95. [(= status CL_OUT_OF_RESOURCES)
  96. (error 'clEnqueueTask "there is a failure to queue the execution instance of kernel on the command-queue because of insufficient resources needed to execute the kernel")]
  97. [(= status CL_MEM_OBJECT_ALLOCATION_FAILURE)
  98. (error 'clEnqueueTask "there is a failure to allocate memory for data store associated with image or buffer objects specified as arguments to kernel")]
  99. [(= status CL_INVALID_EVENT_WAIT_LIST)
  100. (error 'clEnqueueTask "event_wait_list is NULL and num_events_in_wait_list > 0 or event_wait_list is not NULL and num_events_in_wait_list is 0 or if event objects in event_wait_list are not valid events")]
  101. [(= status CL_OUT_OF_HOST_MEMORY)
  102. (error 'clEnqueueTask "there is a failure to allocate resources required by the OpenCL implementation on the host")]
  103. [else
  104. (error 'clEnqueueTask "Invalid error code: ~e" status)])))
  105. (provide/doc
  106. [proc-doc/names clEnqueueTask
  107. (c:-> _cl_command_queue/c _cl_kernel/c (vectorof _cl_event/c)
  108. _cl_event/c)
  109. (cq kernel wait-list)
  110. @{}])
  111. ;;;; XXX clEnqueueNativeKernel