/*! * Copyright 2017 XGBoost contributors */ #ifndef XGBOOST_USE_CUDA // dummy implementation of HostDeviceVector in case CUDA is not used #include #include #include #include #include "./host_device_vector.h" namespace xgboost { template struct HostDeviceVectorImpl { explicit HostDeviceVectorImpl(size_t size, T v) : data_h_(size, v), distribution_() {} HostDeviceVectorImpl(std::initializer_list init) : data_h_(init), distribution_() {} explicit HostDeviceVectorImpl(std::vector init) : data_h_(std::move(init)), distribution_() {} std::vector& Vec() { return data_h_; } GPUDistribution& Dist() { return distribution_; } private: std::vector data_h_; GPUDistribution distribution_; }; template HostDeviceVector::HostDeviceVector(size_t size, T v, GPUDistribution distribution) : impl_(nullptr) { impl_ = new HostDeviceVectorImpl(size, v); } template HostDeviceVector::HostDeviceVector(std::initializer_list init, GPUDistribution distribution) : impl_(nullptr) { impl_ = new HostDeviceVectorImpl(init); } template HostDeviceVector::HostDeviceVector(const std::vector& init, GPUDistribution distribution) : impl_(nullptr) { impl_ = new HostDeviceVectorImpl(init); } template HostDeviceVector::~HostDeviceVector() { HostDeviceVectorImpl* tmp = impl_; impl_ = nullptr; delete tmp; } template HostDeviceVector::HostDeviceVector(const HostDeviceVector& other) : impl_(nullptr) { impl_ = new HostDeviceVectorImpl(*other.impl_); } template HostDeviceVector& HostDeviceVector::operator=(const HostDeviceVector& other) { if (this == &other) { return *this; } delete impl_; impl_ = new HostDeviceVectorImpl(*other.impl_); return *this; } template size_t HostDeviceVector::Size() const { return impl_->Vec().size(); } template GPUSet HostDeviceVector::Devices() const { return GPUSet::Empty(); } template const GPUDistribution& HostDeviceVector::Distribution() const { return impl_->Dist(); } template T* HostDeviceVector::DevicePointer(int device) { return nullptr; } template const T* HostDeviceVector::ConstDevicePointer(int device) const { return nullptr; } template common::Span HostDeviceVector::DeviceSpan(int device) { return common::Span(); } template common::Span HostDeviceVector::ConstDeviceSpan(int device) const { return common::Span(); } template std::vector& HostDeviceVector::HostVector() { return impl_->Vec(); } template const std::vector& HostDeviceVector::ConstHostVector() const { return impl_->Vec(); } template void HostDeviceVector::Resize(size_t new_size, T v) { impl_->Vec().resize(new_size, v); } template size_t HostDeviceVector::DeviceStart(int device) const { return 0; } template size_t HostDeviceVector::DeviceSize(int device) const { return 0; } template void HostDeviceVector::Fill(T v) { std::fill(HostVector().begin(), HostVector().end(), v); } template void HostDeviceVector::Copy(const HostDeviceVector& other) { CHECK_EQ(Size(), other.Size()); std::copy(other.HostVector().begin(), other.HostVector().end(), HostVector().begin()); } template void HostDeviceVector::Copy(const std::vector& other) { CHECK_EQ(Size(), other.size()); std::copy(other.begin(), other.end(), HostVector().begin()); } template void HostDeviceVector::Copy(std::initializer_list other) { CHECK_EQ(Size(), other.size()); std::copy(other.begin(), other.end(), HostVector().begin()); } template bool HostDeviceVector::HostCanAccess(GPUAccess access) const { return true; } template bool HostDeviceVector::DeviceCanAccess(int device, GPUAccess access) const { return false; } template void HostDeviceVector::Reshard(const GPUDistribution& distribution) const { } template void HostDeviceVector::Reshard(GPUSet devices) const { } // explicit instantiations are required, as HostDeviceVector isn't header-only template class HostDeviceVector; template class HostDeviceVector; template class HostDeviceVector; template class HostDeviceVector; template class HostDeviceVector; } // namespace xgboost #endif // XGBOOST_USE_CUDA