CLSETEVENTCALLBACK(3clc)

πŸ“¦
version 1.0~svn33624 Β· 3 versions
, in ubuntu jammy, ubuntu noble

πŸ’– CLSETEVENTCALLBACK πŸ’–

okay bestie, we're in the OpenCL Manual today and this one is the callback-registration girlie. sit down, hydrate, let's go 🫢

✨ NAME ✨

clSetEventCallback β€” registers a user callback function for a specific command execution status. it's giving "hey bestie, text me when this command hits this exact vibe" πŸ’…

cl_int clSetEventCallback(cl_event event,
                          cl_int command_exec_callback_type,
                          void (CL_CALLBACK *pfn_event_notify) (cl_event event, cl_int event_command_exec_status, void *user_data),
                          void *user_data);

🌸 PARAMETERS 🌸

  • event β€” a valid event object. yes it has to be valid, we do not play with stale handles in this house πŸ™ˆ
  • command_exec_callback_type β€” the command execution status you're registering the callback for. the values you can actually register for are CL_SUBMITTED, CL_RUNNING, or CL_COMPLETE. and listen β€” there is no guarantee that callback functions registered for the various execution status values of an event will be called in the exact order that the execution status of a command changes. like, the vibes are chaotic, the ordering is not it. πŸ’€

also real talk: getting a callback for an event with a status other than CL_COMPLETE does not in any way imply that the memory model or execution model as defined by the OpenCL specification has changed. for example, it is not valid to assume that a corresponding memory transfer has completed unless the event is in a state CL_COMPLETE. do not manifest that, it will not come true bestie 😭

the callback function registered for a command_exec_callback_type value of CL_COMPLETE will be called when the command has completed successfully or is abnormally terminated. both paths, same callback, no cap.

  • pfn_event_notify β€” the event callback function that can be registered by the application. this callback function may be called asynchronously by the OpenCL implementation. it is the application's responsibility to ensure that the callback function is thread-safe. (yes that's on you, not on the implementation, sorry gorgeous πŸ’…) the parameters to this callback function are:
    • event is the event object for which the callback function is invoked.
    • event_command_exec_status represents the execution status of command for which this callback function is invoked. see the table of values for param_value for clGetEventInfo(3clc) for the command execution status values. if the callback is called as the result of the command associated with event being abnormally terminated, an appropriate error code for the error that caused the termination will be passed to event_command_exec_status instead. so yeah, that slot might be an error code, plot twist πŸŽ€
    • user_data is a pointer to user supplied data.
  • user_data β€” will be passed as the user_data argument when pfn_notify is called. user_data can be NULL. lowkey the easiest parameter on this whole page πŸ¦‹

πŸ‘‘ NOTES πŸ‘‘

the registered callback function will be called when the execution status of command associated with event changes to an execution status equal to or past the status specified by command_exec_status.

each call to clSetEventCallback registers the specified user callback function on a callback stack associated with event. the order in which the registered user callback functions are called is undefined. it's a stack, it's a mystery, it's iconic in a slightly terrifying way ✨

all callbacks registered for an event object must be called. all enqueued callbacks shall be called before the event object is destroyed. callbacks must return promptly. periodt.

⚠️ the behavior of calling expensive system routines, OpenCL API calls to create contexts or command-queues, or blocking OpenCL operations from the list below, in a callback is undefined. undefined is not a vibe, bestie. do not do it.

if an application needs to wait for completion of a routine from the above list in a callback, please use the non-blocking form of the function, and assign a completion callback to it to do the remainder of your work. that's the move, that's the play 🧚

note that when a callback (or other code) enqueues commands to a command-queue, the commands are not required to begin execution until the queue is flushed. in standard usage, blocking enqueue calls serve this role by implicitly flushing the queue. since blocking calls are not permitted in callbacks, those callbacks that enqueue commands on a command queue should either call clFlush(3clc) on the queue before returning, or arrange for clFlush(3clc) to be called later on another thread. flush it or delegate it, those are your two options πŸ’œ


🌈 ERRORS 🌈

returns CL_SUCCESS if the function is executed successfully. otherwise, it returns one of the following errors:

  • CL_INVALID_EVENT if event is not a valid event object.
  • CL_INVALID_VALUE if pfn_event_notify is NULL or if command_exec_callback_type is not CL_COMPLETE.
  • CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device.
  • CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.

⭐ SPECIFICATION ⭐

OpenCL Specification[1]

πŸ’œ AUTHORS πŸ’œ

The Khronos Group

Copyright Β© 2007-2011 The Khronos Group Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.


πŸ¦‹ NOTES πŸ¦‹

  1. OpenCL Specification page 183, section 5.9 - Event Objects

and that's the whole page, bestie!! this manual page came to you from The Khronos Group, dated 01/14/2021, living in section 3clc of the OpenCL Manual. go forth and register your callbacks responsibly, stay thread-safe, and never block inside a callback, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from