MCPcopy Create free account
hub / github.com/NVIDIA/DALI / SetupImpl

Method SetupImpl

dali/operators/signal/fft/spectrogram_gpu.cc:77–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75 }
76
77 bool SetupImpl(std::vector<OutputDesc> &output_desc, const Workspace &ws) override {
78 auto &in = ws.Input<GPUBackend>(0);
79 KernelContext ctx;
80 ctx.gpu.stream = ws.stream();
81 const auto &in_shape = in.shape();
82 TensorListShape<> out_shape;
83 in_shape_1D.resize(in_shape.num_samples());
84
85 for (int i = 0; i < in_shape.num_samples(); i++) {
86 if (volume(in_shape.tensor_shape_span(i)) == 0) {
87 DALI_FAIL(make_string("Spectogram does not support empty (0-volume) samples. The sample ",
88 i, " shape is ", in_shape[i]));
89 }
90 }
91
92 int axis = -1;
93 if (in_shape.sample_dim() > 1) {
94 for (int i = 0; i < in_shape.num_samples(); i++) {
95 if (axis < 0) {
96 int max_extent = 0;
97 // looking for non-degenerate dimension
98 for (int d = 0; d < in_shape.sample_dim(); d++) {
99 int extent = in_shape.tensor_shape_span(i)[d];
100 if (extent > 1) {
101 if (max_extent > 1) {
102 DALI_FAIL("Spectogram can only be computed from 1D data. If the data is has more "
103 "dimensions, only one dimension can have extent greater than 1, e.g. "
104 "(length x 1), (1 x length), etc. The dimension with extent > 1 must be the same "
105 "one for all samples in the batch.");
106 }
107 axis = d;
108 max_extent = extent;
109 }
110 }
111 in_shape_1D.tensor_shape_span(i)[0] = max_extent;
112 } else {
113 for (int d = 0; d < in_shape.sample_dim(); d++) {
114 if (d != axis && in_shape.tensor_shape_span(i)[d] > 1) {
115 DALI_FAIL("Spectogram can only be computed from 1D data. If the data is has more "
116 "dimensions, only one dimension can have extent greater than 1, e.g. "
117 "(length x 1), (1 x length), etc. The dimension with extent > 1 must be the same "
118 "one for all samples in the batch.");
119 }
120 }
121 in_shape_1D.tensor_shape_span(i)[0] = in_shape.tensor_shape_span(i)[axis];
122 }
123 }
124 if (axis < 0) // degenerate or true 1D case
125 axis = 0;
126 } else {
127 in_shape_1D = in_shape.to_static<1>();
128 axis = 0;
129 }
130
131 auto req = kmgr.Setup<SpectrogramGPU>(0, ctx, in_shape_1D, args);
132 output_desc.resize(1);
133 output_desc[0] = { req.output_shapes[0], DALI_FLOAT };
134

Callers

nothing calls this directly

Calls 8

volumeFunction · 0.85
make_stringFunction · 0.50
streamMethod · 0.45
shapeMethod · 0.45
resizeMethod · 0.45
num_samplesMethod · 0.45
tensor_shape_spanMethod · 0.45
sample_dimMethod · 0.45

Tested by

no test coverage detected