// copy memory from one gpu range to another void copy(const view_type &from, view_type &to) { assert(from.size()==to.size()); assert(!from.overlaps(to)); auto status = cudaMemcpy( reinterpret_cast<void*>(to.begin()), reinterpret_cast<const void*>(from.begin()), from.size()*sizeof(value_type), cudaMemcpyDeviceToDevice ); if(status != cudaSuccess) { std::cerr << util::red("error") << " bad CUDA memcopy, unable to copy " << sizeof(T)*from.size() << " bytes from device to device"; exit(-1); } }
std::pair<CudaEvent, view_type> copy(const ArrayView< value_type, HostCoordinator< value_type, PinnedAllocator< value_type, alignment>>> &from, view_type &to) { assert(from.size()==to.size()); #ifdef VERBOSE using oType = ArrayView< value_type, HostCoordinator< value_type, PinnedAllocator< value_type, alignment>>>; std::cout << util::pretty_printer<DeviceCoordinator>::print(*this) << "::" << util::blue("copy") << "(asynchronous, " << from.size() << ")" << "\n " << util::type_printer<oType>::print() << " @ " << from.data() << util::yellow(" -> ") << util::type_printer<view_type>::print() << " @ " << to.data() << std::endl; #endif auto status = cudaMemcpy( reinterpret_cast<void*>(to.begin()), reinterpret_cast<const void*>(from.begin()), from.size()*sizeof(value_type), cudaMemcpyHostToDevice ); if(status != cudaSuccess) { std::cerr << util::red("error") << " bad CUDA memcopy, unable to copy " << sizeof(T)*from.size() << " bytes from host to device"; exit(-1); } CudaEvent event; return std::make_pair(event, to); }
// construct as a copy of another range Array(view_type const& other) : base(coordinator_type().allocate(other.size())) { #ifdef VERBOSE std::cerr << util::green("Array(other&)") + " other = " << util::pretty_printer<view_type>::print(other) << std::endl; #endif coordinator_.copy(static_cast<base const&>(other), *this); }
void free(view_type& rng) { Allocator allocator; if(rng.data()) allocator.deallocate(rng.data(), rng.size()); #ifdef VERBOSE std::cerr << util::type_printer<DeviceCoordinator>::print() << "::free()" << std::endl; #endif impl::reset(rng); }
// fill memory void set(view_type &rng, value_type value) { gpu::fill<value_type>(rng.data(), value, rng.size()); }