18 #ifndef viskores_cont_exec_ArrayHandleExecutionManager_h
19 #define viskores_cont_exec_ArrayHandleExecutionManager_h
37 template <
typename T,
typename Storage>
38 class ArrayHandleExecutionManagerBase
41 using StorageType = viskores::cont::internal::Storage<T, Storage>;
44 template <
typename DeviceAdapter>
48 using ArrayTransferType = viskores::cont::internal::ArrayTransfer<T, Storage, DeviceAdapter>;
51 using Portal =
typename ArrayTransferType::PortalExecution;
52 using PortalConst =
typename ArrayTransferType::PortalConstExecution;
61 using PortalControl =
typename StorageType::PortalType;
62 using PortalConstControl =
typename StorageType::PortalConstType;
65 virtual ~ArrayHandleExecutionManagerBase() {}
71 viskores::Id GetNumberOfValues()
const {
return this->GetNumberOfValuesImpl(); }
79 template <
typename DeviceAdapter>
80 VISKORES_CONT typename ExecutionTypes<DeviceAdapter>::PortalConst
83 this->VerifyDeviceAdapter(DeviceAdapter());
85 typename ExecutionTypes<DeviceAdapter>::PortalConst portal;
86 this->PrepareForInputImpl(updateData, &portal, token);
96 template <
typename DeviceAdapter>
100 this->VerifyDeviceAdapter(DeviceAdapter());
102 typename ExecutionTypes<DeviceAdapter>::Portal portal;
103 this->PrepareForInPlaceImpl(updateData, &portal, token);
114 template <
typename DeviceAdapter>
118 this->VerifyDeviceAdapter(DeviceAdapter());
120 typename ExecutionTypes<DeviceAdapter>::Portal portal;
121 this->PrepareForOutputImpl(numberOfValues, &portal, token);
133 void RetrieveOutputData(StorageType* storage)
const { this->RetrieveOutputDataImpl(storage); }
145 void Shrink(
viskores::Id numberOfValues) { this->ShrinkImpl(numberOfValues); }
151 void ReleaseResources() { this->ReleaseResourcesImpl(); }
153 template <
typename DeviceAdapter>
154 VISKORES_CONT bool IsDeviceAdapter(DeviceAdapter device)
const
156 return this->IsDeviceAdapterImpl(device);
160 DeviceAdapterId GetDeviceAdapterId()
const {
return this->GetDeviceAdapterIdImpl(); }
165 virtual void PrepareForInputImpl(
bool updateData,
166 void* portalExecutionVoid,
169 virtual void PrepareForInPlaceImpl(
bool updateData,
170 void* portalExecutionVoid,
173 virtual void PrepareForOutputImpl(
viskores::Id numberOfValues,
174 void* portalExecution,
177 virtual void RetrieveOutputDataImpl(StorageType* storage)
const = 0;
179 virtual void ShrinkImpl(
Id numberOfValues) = 0;
181 virtual void ReleaseResourcesImpl() = 0;
185 virtual DeviceAdapterId GetDeviceAdapterIdImpl()
const = 0;
188 template <
typename DeviceAdapter>
189 VISKORES_CONT void VerifyDeviceAdapter(DeviceAdapter device)
const
191 if (!this->IsDeviceAdapter(device))
205 template <
typename T,
typename Storage,
typename DeviceAdapter>
206 class ArrayHandleExecutionManager :
public ArrayHandleExecutionManagerBase<T, Storage>
208 using Superclass = ArrayHandleExecutionManagerBase<T, Storage>;
209 using ArrayTransferType = viskores::cont::internal::ArrayTransfer<T, Storage, DeviceAdapter>;
210 using StorageType = viskores::cont::internal::Storage<T, Storage>;
213 using PortalControl =
typename ArrayTransferType::PortalControl;
214 using PortalConstControl =
typename ArrayTransferType::PortalConstControl;
216 using PortalExecution =
typename ArrayTransferType::PortalExecution;
217 using PortalConstExecution =
typename ArrayTransferType::PortalConstExecution;
220 ArrayHandleExecutionManager(StorageType* storage)
227 viskores::Id GetNumberOfValuesImpl()
const {
return this->Transfer.GetNumberOfValues(); }
232 PortalConstExecution portal = this->Transfer.PrepareForInput(updateData, token);
233 *
reinterpret_cast<PortalConstExecution*
>(portalExecutionVoid) = portal;
237 void PrepareForInPlaceImpl(
bool updateData,
238 void* portalExecutionVoid,
241 PortalExecution portal = this->Transfer.PrepareForInPlace(updateData, token);
242 *
reinterpret_cast<PortalExecution*
>(portalExecutionVoid) = portal;
247 void* portalExecutionVoid,
250 PortalExecution portal = this->Transfer.PrepareForOutput(numberOfValues, token);
251 *
reinterpret_cast<PortalExecution*
>(portalExecutionVoid) = portal;
255 void RetrieveOutputDataImpl(StorageType* storage)
const
257 this->Transfer.RetrieveOutputData(storage);
261 void ShrinkImpl(
Id numberOfValues) { this->Transfer.Shrink(numberOfValues); }
264 void ReleaseResourcesImpl() { this->Transfer.ReleaseResources(); }
267 bool IsDeviceAdapterImpl(
const DeviceAdapterId&
id)
const {
return id == DeviceAdapter(); }
270 DeviceAdapterId GetDeviceAdapterIdImpl()
const {
return DeviceAdapter(); }
273 ArrayTransferType Transfer;
279 #endif //viskores_cont_exec_ArrayHandleExecutionManager_h