Runtime: Add CL base object for all cl objects

Graphics / Beignet - Junyan He [intel.com] - 2 September 2016 04:34 UTC

The runtime code is a little verbose in CL object handle. Every CL objects should have a reference, a lock to protect itself and an ICD dispatcher. We can organize them to a struct and place it at the beginning of each CL object. This base object is also used to protect the CL objects MT safe. CL_OBJECT_LOCK/CL_OBJECT_UNLOCK macro will lock/unlock objects, but we should use them within one function call, and the critical region should be short. We add CL_OBJECT_TAKE_OWNERSHIP/CL_OBJECT_RELEASE_OWNERSHIP macro to own the object for a long time. CL_OBJECT_TAKE_OWNERSHIP will not hold the lock and so will not cause deadlock problems. For example, when we call NDRange on some memobj, we should take the ownship of the memobj. If another thread call NDRange on the same memobj, we should return some error like CL_OUT_OF_RESOURCE to users and protect the memobj from accessing simultaneously.

V2: Add atomic_read to avoid atomic_add misuse.

d743c18 Runtime: Add CL base object for all cl objects.
src/CMakeLists.txt | 1 +
src/cl_base_object.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/cl_base_object.h | 77 +++++++++++++++++++++++++++++++++++++
src/cl_utils.h | 3 ++
4 files changed, 183 insertions(+)

Upstream: cgit.freedesktop.org


  • Share