MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / array

Function array

include/af/oneapi.h:316–343  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

314 \note Set \p retain to true if the memory originates from a cl::Buffer object
315 */
316 static inline af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
317 {
318 const unsigned ndims = (unsigned)idims.ndims();
319 const dim_t *dims = idims.get();
320
321 cl_context context;
322 cl_int clerr = clGetMemObjectInfo(buf, CL_MEM_CONTEXT, sizeof(cl_context), &context, NULL);
323 if (clerr != CL_SUCCESS) {
324 throw af::exception("Failed to get context from cl_mem object \"buf\" ");
325 }
326
327 if (context != getContext()) {
328 throw(af::exception("Context mismatch between input \"buf\" and arrayfire"));
329 }
330
331
332 if (retain) clerr = clRetainMemObject(buf);
333
334 af_array out;
335 af_err err = af_device_array(&out, buf, ndims, dims, type);
336
337 if (err != AF_SUCCESS || clerr != CL_SUCCESS) {
338 if (retain && clerr == CL_SUCCESS) clReleaseMemObject(buf);
339 throw af::exception("Failed to create device array");
340 }
341
342 return af::array(out);
343 }
344
345 /**
346 Create an af::array object from an OpenCL cl_mem buffer

Callers

nothing calls this directly

Calls 5

getContextFunction · 0.70
dim4Class · 0.70
af_device_arrayFunction · 0.50
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected