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

Function checkAndMigrate

src/backend/opencl/Array.cpp:196–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194
195template<typename T>
196void checkAndMigrate(Array<T> &arr) {
197 int arr_id = arr.getDevId();
198 int cur_id = detail::getActiveDeviceId();
199 if (!isDeviceBufferAccessible(arr_id, cur_id)) {
200 auto getLogger = [&] { return spdlog::get("platform"); };
201 AF_TRACE("Migrating array from {} to {}.", arr_id, cur_id);
202 auto migrated_data = memAlloc<T>(arr.elements());
203 void *mapped_migrated_buffer = getQueue().enqueueMapBuffer(
204 *migrated_data, CL_TRUE, CL_MAP_WRITE_INVALIDATE_REGION, 0,
205 sizeof(T) * arr.elements());
206 setDevice(arr_id);
207 Buffer &buf = *arr.get();
208 getQueue().enqueueReadBuffer(buf, CL_TRUE, 0,
209 sizeof(T) * arr.elements(),
210 mapped_migrated_buffer);
211 setDevice(cur_id);
212 getQueue().enqueueUnmapMemObject(*migrated_data,
213 mapped_migrated_buffer);
214 arr.data.reset(migrated_data.release(), bufferFree);
215 arr.setId(cur_id);
216 }
217}
218
219template<typename T>
220void Array<T>::eval() {

Callers

nothing calls this directly

Calls 10

getDevIdMethod · 0.80
resetMethod · 0.80
getActiveDeviceIdFunction · 0.70
isDeviceBufferAccessibleFunction · 0.70
setDeviceFunction · 0.70
getFunction · 0.50
getQueueFunction · 0.50
elementsMethod · 0.45
getMethod · 0.45
setIdMethod · 0.45

Tested by

no test coverage detected