-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdevice_raw_buffer.h
More file actions
73 lines (53 loc) · 1.96 KB
/
Copy pathdevice_raw_buffer.h
File metadata and controls
73 lines (53 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include <condition_variable>
#include <cuda.h>
#include <cuda_runtime.h>
#include <mutex>
#include "raw_buffer.h"
using namespace std;
/*
The DeviceRawBuffer is designed for a single producer thread to produce
RawBuffers, and a single consumer thread to use the buffer for GPU calculations.
Its format is row-major:
input[block][antenna][coarse-channel][time-within-block][polarization][real or imag]
The states are:
unused: no producer or consumer is using the data
copying: data is currently being copied into this buffer from a raw buffer
ready: the consumer thread is using the data
Access to state is protected by the mutex.
*/
enum class DeviceRawBufferState { unused, copying, ready };
class DeviceRawBuffer {
public:
const int num_blocks;
const int num_antennas;
const int num_coarse_channels;
const int timesteps_per_block;
const int num_polarizations;
int8_t* data;
size_t size;
DeviceRawBuffer(int num_blocks, int num_antennas, int num_coarse_channels,
int timesteps_per_block, int num_polarizations);
~DeviceRawBuffer();
void copyFromAsync(const RawBuffer& source);
// Wait until a copy finishes
void waitUntilReady();
// Wait until the consumer thread is done with this buffer
void waitUntilUnused();
// Return the state from ready to unused
void release();
static void CUDART_CB staticCopyCallback(cudaStream_t stream,
cudaError_t status,
void *device_raw_buffer);
static void CUDART_CB staticRelease(cudaStream_t stream,
cudaError_t status,
void *device_raw_buffer);
private:
// This stream is just for this raw buffer; the state tracks concurrency
cudaStream_t stream;
// Called when a copy completes
void copyCallback();
DeviceRawBufferState state;
mutex m;
condition_variable cv;
};