Create an af::array object from an OpenCL cl_mem buffer \param[in] idims the dimensions of the buffer \param[in] buf the OpenCL memory object \param[in] type the data type contained in the buffer \param[in] retain if true, instructs ArrayFire to retain the memory object \returns an array object created from the OpenCL buffer \note Set \p retain to true if the memory originates from a cl::B
| 328 | \note Set \p retain to true if the memory originates from a cl::Buffer object |
| 329 | */ |
| 330 | static inline af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false) |
| 331 | { |
| 332 | const unsigned ndims = (unsigned)idims.ndims(); |
| 333 | const dim_t *dims = idims.get(); |
| 334 | |
| 335 | cl_context context; |
| 336 | cl_int clerr = clGetMemObjectInfo(buf, CL_MEM_CONTEXT, sizeof(cl_context), &context, NULL); |
| 337 | if (clerr != CL_SUCCESS) { |
| 338 | throw af::exception("Failed to get context from cl_mem object \"buf\" "); |
| 339 | } |
| 340 | |
| 341 | if (context != getContext()) { |
| 342 | throw(af::exception("Context mismatch between input \"buf\" and arrayfire")); |
| 343 | } |
| 344 | |
| 345 | |
| 346 | if (retain) clerr = clRetainMemObject(buf); |
| 347 | |
| 348 | af_array out; |
| 349 | af_err err = af_device_array(&out, buf, ndims, dims, type); |
| 350 | |
| 351 | if (err != AF_SUCCESS || clerr != CL_SUCCESS) { |
| 352 | if (retain && clerr == CL_SUCCESS) clReleaseMemObject(buf); |
| 353 | throw af::exception("Failed to create device array"); |
| 354 | } |
| 355 | |
| 356 | return af::array(out); |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | Create an af::array object from an OpenCL cl_mem buffer |
nothing calls this directly
no test coverage detected