Repository navigation
Expand file tree
/
Copy pathgpu_jpeg_decoder.h
More file actions
88 lines (73 loc) · 2.6 KB
/
Copy pathgpu_jpeg_decoder.h
File metadata and controls
88 lines (73 loc) · 2.6 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/************************************************
* Copyright MaybeShewill-CV. All Rights Reserved.
* Author: MaybeShewill-CV
* File: gpu_jpeg_decoder.h
* Date: 26-9-20
************************************************/
#ifndef MORTRED_MODELS_BACKEND_GPU_JPEG_DECODER_H
#define MORTRED_MODELS_BACKEND_GPU_JPEG_DECODER_H
#include <atomic>
#include <cstddef>
#include <memory>
#include <string>
#include "models/backend/gpu_preprocess_desc.h"
namespace mortred {
namespace models {
namespace backend {
namespace gpu_jpeg {
/*** Decode backends that actually run. nvJPEG was removed with the old ladder. */
enum Backend {
JPEGGPU = 0,
CPU_REDUCED,
CPU_FULL,
FALLBACK,
BACKEND_COUNT
};
/*** Global request counters per backend, readable by the metrics layer.
* Incremented by the decode layer on every request. */
extern std::atomic<uint64_t> g_request_count[BACKEND_COUNT];
/*** Prometheus text for /metrics. */
std::string render_decode_metrics();
/*** Device tensor produced by one worker's slot. The pointers alias that
* slot's buffers. They stay valid until this same slot decodes again or
* closes, which the worker lease only allows after the consumer stream has
* synchronized (TrtSession::run does that before returning). */
struct GpuPipelineResult {
void* device_input = nullptr;
void* device_gray = nullptr;
int out_w = 0, out_h = 0;
int src_w = 0, src_h = 0;
void* ready_event = nullptr;
bool valid = false;
};
/*** One jpeggpu decoder, stream, event and set of buffers. Owned by a single
* worker. The worker lease is the exclusion: run() does not overlap on the
* same slot, and the slot is reused only after the consumer synchronizes.
* No mutex. Not safe to share across workers. */
class GpuDecodeSlot {
public:
GpuDecodeSlot();
~GpuDecodeSlot();
GpuDecodeSlot(const GpuDecodeSlot&) = delete;
GpuDecodeSlot& operator=(const GpuDecodeSlot&) = delete;
GpuDecodeSlot(GpuDecodeSlot&&) = delete;
GpuDecodeSlot& operator=(GpuDecodeSlot&&) = delete;
/*** Probe jpeggpu on a temporary decoder, then keep a private one.
* Safe to call once from the worker's init thread. */
bool open();
void close();
bool ready() const;
GpuPipelineResult decode_and_preprocess(
const unsigned char* data, size_t size,
int network_w, int network_h,
const GpuPreprocessDescriptor& desc,
std::string* err);
private:
struct State;
std::unique_ptr<State> state_;
};
} // namespace gpu_jpeg
} // namespace backend
} // namespace models
} // namespace mortred
#endif // MORTRED_MODELS_BACKEND_GPU_JPEG_DECODER_H