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

Function array

include/af/opencl.h:330–357  ·  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

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

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