isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
DataStream.h
1 #pragma once
2 
3 #include <isce3/cuda/core/Event.h>
4 #include <isce3/cuda/core/Stream.h>
5 #include <isce3/io/Raster.h>
6 #include <string>
7 #include <thrust/host_vector.h>
8 #include <thrust/system/cuda/experimental/pinned_allocator.h>
9 
10 namespace isce3 { namespace cuda { namespace io {
11 
12 // thrust::host_vector whose data buffer uses page-locked memory
13 template<typename T>
14 using pinned_host_vector = thrust::host_vector<T,
15  thrust::system::cuda::experimental::pinned_allocator<T>>;
16 
17 // callback for asynchronously writing to files via std::ofstream
19 private:
20  fstreamCallback() = default;
21 
22  fstreamCallback(const std::string * filename,
23  const char * buffer,
24  std::size_t offset,
25  std::size_t count);
26 
27  // interface for cudaStreamAddCallback
28  // casts *obj* to (fstreamCallback *) and calls write()
29  static
30  void CUDART_CB cb_write(cudaStream_t, cudaError_t, void * obj);
31 
32  // write the contents of *buffer* to file at *filename* via std::ofstream
33  void write();
34 
35  const std::string * filename;
36  const char * buffer;
37  std::size_t offset;
38  std::size_t count;
39 
40  friend class FileDataStream;
41 };
42 
43 // callback for asynchronously writing to Raster objects
45 private:
46  RasterCallback() = default;
47 
49  char * buffer,
50  std::size_t col,
51  std::size_t row,
52  std::size_t width,
53  std::size_t length);
54 
55  // interface for cudaStreamAddCallback
56  // casts *obj* to (RasterCallback *) and calls setBlock()
57  template<typename T>
58  static
59  void CUDART_CB cb_setBlock(cudaStream_t, cudaError_t, void * obj);
60 
61  // forwards members as arguments to Raster::setBlock()
62  template<typename T>
63  void setBlock();
64 
65  isce3::io::Raster * raster;
66  char * buffer;
67  std::size_t col;
68  std::size_t row;
69  std::size_t width;
70  std::size_t length;
71 
72  friend class RasterDataStream;
73 };
74 
80 public:
81  FileDataStream() = default;
82 
90  FileDataStream(const std::string & filename,
92  std::size_t buffer_size = 0);
93 
95  const std::string & filename() const;
96 
98  void set_filename(const std::string &);
99 
102 
105 
107  std::size_t buffer_size() const;
108 
110  void resize_buffer(std::size_t buffer_size);
111 
125  void load(void * dst, std::size_t offset, std::size_t count);
126 
140  void store(const void * src, std::size_t offset, std::size_t count);
141 
142 private:
143  std::string _filename;
144  isce3::cuda::core::Stream _stream = 0;
146  pinned_host_vector<char> _buffer;
147  fstreamCallback _callback;
148 };
149 
155 public:
156  RasterDataStream() = default;
157 
167  std::size_t buffer_size = 0);
168 
170  isce3::io::Raster * raster() const;
171 
174 
177 
180 
182  std::size_t buffer_size() const;
183 
185  void resize_buffer(std::size_t buffer_size);
186 
203  template<typename T>
204  void load(T * dst,
205  std::size_t col,
206  std::size_t row,
207  std::size_t width,
208  std::size_t length);
209 
226  template<typename T>
227  void store(const T * src,
228  std::size_t col,
229  std::size_t row,
230  std::size_t width,
231  std::size_t length);
232 
233 private:
234  isce3::io::Raster * _raster;
235  isce3::cuda::core::Stream _stream = 0;
237  pinned_host_vector<char> _buffer;
238  RasterCallback _callback;
239 };
240 
241 }}}
242 
243 #define ISCE_CUDA_IO_DATASTREAM_ICC
244 #include "DataStream.icc"
245 #undef ISCE_CUDA_IO_DATASTREAM_ICC
Definition: DataStream.h:44
isce3::cuda::core::Stream stream() const
Get associated CUDA stream object.
Definition: DataStream.icc:226
void store(const T *src, std::size_t col, std::size_t row, std::size_t width, std::size_t length)
Write a block of data from the current device to the Raster asynchronously.
Definition: DataStream.icc:285
Utility class for asynchronously reading/writing between files and device memory. ...
Definition: DataStream.h:79
isce3::cuda::core::Stream stream() const
Get associated CUDA stream object.
Definition: DataStream.icc:108
std::size_t buffer_size() const
Get stream buffer size in bytes.
Definition: DataStream.icc:241
void set_stream(isce3::cuda::core::Stream stream)
Set CUDA stream.
Definition: DataStream.icc:114
void set_stream(isce3::cuda::core::Stream stream)
Set CUDA stream.
Definition: DataStream.icc:232
void set_filename(const std::string &)
Set path to file.
Definition: DataStream.icc:99
Definition: DataStream.h:18
Utility class for asynchronously reading/writing between Rasters and device memory.
Definition: DataStream.h:154
void load(void *dst, std::size_t offset, std::size_t count)
Read data and copy to the current device asynchronously.
Definition: DataStream.icc:138
void store(const void *src, std::size_t offset, std::size_t count)
Write data from the current device to the file asynchronously.
Definition: DataStream.icc:173
Thin RAII wrapper around cudaEvent_t.
Definition: Event.h:8
isce3::io::Raster * raster() const
Get pointer to Raster object.
Definition: DataStream.icc:211
void resize_buffer(std::size_t buffer_size)
Set stream buffer size in bytes.
Definition: DataStream.icc:129
const std::string & filename() const
Get path to file.
Definition: DataStream.icc:93
std::size_t buffer_size() const
Get stream buffer size in bytes.
Definition: DataStream.icc:123
void set_raster(isce3::io::Raster *)
Set raster.
Definition: DataStream.icc:217
void load(T *dst, std::size_t col, std::size_t row, std::size_t width, std::size_t length)
Read a block of data from the Raster and copy to the current device asynchronously.
Definition: DataStream.icc:257
void resize_buffer(std::size_t buffer_size)
Set stream buffer size in bytes.
Definition: DataStream.icc:247
Data structure meant to handle Raster I/O operations.
Definition: Raster.h:34
Thin RAII wrapper around cudaStream_t.
Definition: Stream.h:10

Generated for ISCE3.0 by doxygen 1.8.5.