/*! * Copyright 2017 XGBoost contributors */ #ifndef XGBOOST_USE_CUDA // dummy implementation of HostDeviceVector in case CUDA is not used #include #include #include #include #include #include "xgboost/tree_model.h" #include "xgboost/host_device_vector.h" namespace xgboost { template struct HostDeviceVectorImpl { explicit HostDeviceVectorImpl(size_t size, T v) : data_h_(size, v) {} HostDeviceVectorImpl(std::initializer_list init) : data_h_(init) {} explicit HostDeviceVectorImpl(std::vector init) : data_h_(std::move(init)) {} HostDeviceVectorImpl(HostDeviceVectorImpl&& that) : data_h_(std::move(that.data_h_)) {} void Swap(HostDeviceVectorImpl &other) { data_h_.swap(other.data_h_); } std::vector& Vec() { return data_h_; } private: std::vector data_h_; }; template HostDeviceVector::HostDeviceVector(size_t size, T v, int) : impl_(nullptr) { impl_ = new HostDeviceVectorImpl(size, v); } template HostDeviceVector::HostDeviceVector(std::initializer_list init, int) : impl_(nullptr) { impl_ = new HostDeviceVectorImpl(init); } template HostDeviceVector::HostDeviceVector(const std::vector& init, int) : impl_(nullptr) { impl_ = new HostDeviceVectorImpl(init); } template HostDeviceVector::HostDeviceVector(HostDeviceVector&& that) { impl_ = new HostDeviceVectorImpl(std::move(*that.impl_)); } template HostDeviceVector& HostDeviceVector::operator=(HostDeviceVector&& that) { if (this == &that) { return *this; } std::unique_ptr> new_impl( new HostDeviceVectorImpl(std::move(*that.impl_))); delete impl_; impl_ = new_impl.release(); return *this; } template HostDeviceVector::~HostDeviceVector() { delete impl_; impl_ = nullptr; } template GPUAccess HostDeviceVector::DeviceAccess() const { return kNone; } template size_t HostDeviceVector::Size() const { return impl_->Vec().size(); } template int HostDeviceVector::DeviceIdx() const { return -1; } template T* HostDeviceVector::DevicePointer() { return nullptr; } template const T* HostDeviceVector::ConstDevicePointer() const { return nullptr; } template common::Span HostDeviceVector::DeviceSpan() { return common::Span(); } template common::Span HostDeviceVector::ConstDeviceSpan() 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 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 void HostDeviceVector::Extend(HostDeviceVector const& other) { auto ori_size = this->Size(); this->HostVector().resize(ori_size + other.Size()); std::copy(other.ConstHostVector().cbegin(), other.ConstHostVector().cend(), this->HostVector().begin() + ori_size); } template bool HostDeviceVector::HostCanRead() const { return true; } template bool HostDeviceVector::HostCanWrite() const { return true; } template bool HostDeviceVector::DeviceCanRead() const { return false; } template bool HostDeviceVector::DeviceCanWrite() const { return false; } template void HostDeviceVector::SetDevice(int) const {} // explicit instantiations are required, as HostDeviceVector isn't header-only template class HostDeviceVector; template class HostDeviceVector; template class HostDeviceVector; template class HostDeviceVector; // bst_node_t template class HostDeviceVector; template class HostDeviceVector; template class HostDeviceVector; template class HostDeviceVector; // bst_row_t template class HostDeviceVector; // bst_feature_t template class HostDeviceVector; #if defined(__APPLE__) || defined(__EMSCRIPTEN__) /* * On OSX: * * typedef unsigned int uint32_t; * typedef unsigned long long uint64_t; * typedef unsigned long __darwin_size_t; * * On Emscripten: * typedef unsigned long size_t; */ template class HostDeviceVector; #endif // defined(__APPLE__) } // namespace xgboost #endif // XGBOOST_USE_CUDA