16 #include "atlas/library/config.h" 17 #include "atlas/runtime/Exception.h" 19 #if ATLAS_GRIDTOOLS_STORAGE_BACKEND_CUDA 20 #include <cuda_runtime.h> 31 Vector(
idx_t N = 0 ) : data_( N ?
new T[N] :
nullptr ), data_gpu_(
nullptr ), size_( N ) {}
33 void resize_impl(
idx_t N ) {
34 ATLAS_ASSERT( not data_gpu_,
"we can not resize a vector after has been cloned to device" );
35 ATLAS_ASSERT( N >= size_ );
40 for (
idx_t c = 0; c < size_; ++c ) {
48 void resize(
idx_t N ) {
53 void resize(
idx_t N, T val ) {
55 for (
idx_t c = size_; c < N; ++c ) {
64 #if ATLAS_GRIDTOOLS_STORAGE_BACKEND_CUDA 65 ::cudaMalloc( (
void**)( &data_gpu_ ),
sizeof( T* ) * size_ );
67 T* buff =
new T[size_];
69 for (
idx_t i = 0; i < size(); ++i ) {
70 data_[i]->updateDevice();
71 buff[i] = data_[i]->gpu_object_ptr();
73 ::cudaMemcpy( data_gpu_, buff,
sizeof( T* ) * size_, cudaMemcpyHostToDevice );
81 ATLAS_ASSERT( size_gpu_ == size_ );
82 #if ATLAS_GRIDTOOLS_STORAGE_BACKEND_CUDA 83 for (
idx_t i = 0; i < size(); ++i ) {
84 data_[i]->updateDevice();
85 assert( data_gpu_[i] == data_[i]->gpu_object_ptr() );
91 ATLAS_ASSERT( data_gpu_ !=
nullptr );
93 #if ATLAS_GRIDTOOLS_STORAGE_BACKEND_CUDA 95 for (
idx_t i = 0; i < size(); ++i ) {
96 data_[i]->updateHost();
101 T* gpu_object_ptr() {
return data_gpu_; }
103 T* data() {
return data_; }
104 T* data_gpu() {
return data_gpu_; }
106 idx_t size()
const {
return size_; }
115 template <
typename T>
118 VectorView() : vector_(
nullptr ), data_(
nullptr ), size_( 0 ) {}
122 T& operator[](
idx_t idx ) {
123 assert( idx < size_ );
129 T
const& operator[](
idx_t idx )
const {
130 assert( idx < size_ );
134 T base() {
return *data_; }
137 idx_t size()
const {
return size_; }
139 bool is_valid(
Vector<T>& vector ) {
return ( &vector ) == vector_ && ( data_ != nullptr ); }
147 template <
typename T>
152 template <
typename T>
Definition: CubedSphereMeshGenerator.h:25
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42