Skip to content

Commit ffa79ac

Browse files
committed
vcomp/cuda_dxt: improve error print
- use logger - print CUDA error string
1 parent 193c8d5 commit ffa79ac

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

src/video_compress/cuda_dxt.cpp

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3636
*/
3737

38-
#include <cstdio> // for printf, fprintf, stderr
38+
#include <cstdio> // for printf, stderr
3939
#include <cstdlib> // for free, malloc
4040
#include <memory> // for shared_ptr
4141

@@ -52,6 +52,15 @@
5252
#include "video_compress.h"
5353
#include "video_frame.h" // for vf_get_tile, video_desc_from_f...
5454

55+
#define MOD_NAME "[CUDA DXT] "
56+
57+
#define CHECK_CUDA(cmd, msg, action) \
58+
if ((cmd) != CUDA_WRAPPER_SUCCESS) { \
59+
MSG(ERROR, "%s: %s\n", msg, cuda_wrapper_last_error_string()); \
60+
action; \
61+
}
62+
63+
5564
using namespace std;
5665

5766
namespace {
@@ -144,25 +153,22 @@ static bool configure_with(struct state_video_compress_cuda_dxt *s, struct video
144153
codec_t supported_codecs[] = { RGB, UYVY, VIDEO_CODEC_NONE };
145154
s->decoder = get_best_decoder_from(desc.color_spec, supported_codecs, &s->in_codec);
146155
if (!s->decoder) {
147-
fprintf(stderr, "Unsupported codec: %s\n", get_codec_name(desc.color_spec));
156+
MSG(ERROR, "Unsupported codec: %s\n",
157+
get_codec_name(desc.color_spec));
148158
return false;
149159
}
150160

151161
if (s->in_codec == UYVY) {
152-
if (CUDA_WRAPPER_SUCCESS != cuda_wrapper_malloc((void **) &s->cuda_uyvy_buffer,
153-
desc.width * desc.height * 2)) {
154-
fprintf(stderr, "Could not allocate CUDA UYVY buffer.\n");
155-
return false;
156-
}
162+
CHECK_CUDA(cuda_wrapper_malloc((void **) &s->cuda_uyvy_buffer,
163+
desc.width * desc.height * 2),
164+
"Could not allocate CUDA UYVY buffer", return false);
157165
}
158166

159167
s->in_buffer = (char *) malloc(desc.width * desc.height * 3);
160168

161-
if (CUDA_WRAPPER_SUCCESS != cuda_wrapper_malloc((void **) &s->cuda_in_buffer,
162-
desc.width * desc.height * 3)) {
163-
fprintf(stderr, "Could not allocate CUDA output buffer.\n");
164-
return false;
165-
}
169+
CHECK_CUDA(cuda_wrapper_malloc((void **) &s->cuda_in_buffer,
170+
desc.width * desc.height * 3),
171+
"Could not allocate CUDA output buffer", return false);
166172

167173
struct video_desc compressed_desc = desc;
168174
compressed_desc.color_spec = s->out_codec;
@@ -171,12 +177,8 @@ static bool configure_with(struct state_video_compress_cuda_dxt *s, struct video
171177

172178
s->pool.reconfigure(compressed_desc, data_len);
173179

174-
if (CUDA_WRAPPER_SUCCESS != cuda_wrapper_malloc((void **)
175-
&s->cuda_out_buffer,
176-
data_len)) {
177-
fprintf(stderr, "Could not allocate CUDA output buffer.\n");
178-
return false;
179-
}
180+
CHECK_CUDA(cuda_wrapper_malloc((void **) &s->cuda_out_buffer, data_len),
181+
"Could not allocate CUDA output buffer", return false);
180182

181183
return true;
182184
}
@@ -196,7 +198,7 @@ shared_ptr<video_frame> cuda_dxt_compress_tile(void *state, shared_ptr<video_fra
196198
if(configure_with(s, video_desc_from_frame(tx.get()))) {
197199
s->saved_desc = video_desc_from_frame(tx.get());
198200
} else {
199-
fprintf(stderr, "[CUDA DXT] Reconfiguration failed!\n");
201+
MSG(ERROR, "Reconfiguration failed!\n");
200202
return NULL;
201203
}
202204
}
@@ -218,24 +220,22 @@ shared_ptr<video_frame> cuda_dxt_compress_tile(void *state, shared_ptr<video_fra
218220
}
219221

220222
if (s->in_codec == UYVY) {
221-
if (cuda_wrapper_memcpy(s->cuda_uyvy_buffer, in_buffer, tx->tiles[0].width *
222-
tx->tiles[0].height * 2,
223-
CUDA_WRAPPER_MEMCPY_HOST_TO_DEVICE) != CUDA_WRAPPER_SUCCESS) {
224-
fprintf(stderr, "Memcpy failed: %s\n", cuda_wrapper_last_error_string());
225-
return NULL;
226-
}
227-
if (cuda_yuv422_to_yuv444(s->cuda_uyvy_buffer, s->cuda_in_buffer,
228-
tx->tiles[0].width *
229-
tx->tiles[0].height, 0) != CUDA_WRAPPER_SUCCESS) {
230-
fprintf(stderr, "Kernel failed: %s\n", cuda_wrapper_last_error_string());
231-
}
223+
CHECK_CUDA(cuda_wrapper_memcpy(
224+
s->cuda_uyvy_buffer, in_buffer,
225+
tx->tiles[0].width * tx->tiles[0].height * 2,
226+
CUDA_WRAPPER_MEMCPY_HOST_TO_DEVICE),
227+
"Memcpy failed", return nullptr);
228+
229+
CHECK_CUDA(cuda_yuv422_to_yuv444(
230+
s->cuda_uyvy_buffer, s->cuda_in_buffer,
231+
tx->tiles[0].width * tx->tiles[0].height, 0),
232+
"Kernel failed", return nullptr);
232233
} else {
233-
if (cuda_wrapper_memcpy(s->cuda_in_buffer, in_buffer, tx->tiles[0].width *
234-
tx->tiles[0].height * 3,
235-
CUDA_WRAPPER_MEMCPY_HOST_TO_DEVICE) != CUDA_WRAPPER_SUCCESS) {
236-
fprintf(stderr, "Memcpy failed: %s\n", cuda_wrapper_last_error_string());
237-
return NULL;
238-
}
234+
CHECK_CUDA(cuda_wrapper_memcpy(
235+
s->cuda_in_buffer, in_buffer,
236+
tx->tiles[0].width * tx->tiles[0].height * 3,
237+
CUDA_WRAPPER_MEMCPY_HOST_TO_DEVICE),
238+
"Memcpy failed", return nullptr);
239239
}
240240

241241
int (*cuda_dxt_enc_func)(const void * src, void * out, int size_x, int size_y,
@@ -254,21 +254,16 @@ shared_ptr<video_frame> cuda_dxt_compress_tile(void *state, shared_ptr<video_fra
254254
cuda_dxt_enc_func = cuda_yuv_to_dxt6;
255255
}
256256
}
257-
int ret = cuda_dxt_enc_func(s->cuda_in_buffer, s->cuda_out_buffer,
258-
s->saved_desc.width, s->saved_desc.height, 0);
259-
if (ret != 0) {
260-
fprintf(stderr, "Encoding failed: %s\n", cuda_wrapper_last_error_string());
261-
return NULL;
262-
}
257+
CHECK_CUDA(cuda_dxt_enc_func(s->cuda_in_buffer, s->cuda_out_buffer,
258+
s->saved_desc.width, s->saved_desc.height,
259+
0),
260+
"Encoding failed", return nullptr);
263261

264262
shared_ptr<video_frame> out = s->pool.get_frame();
265-
if (cuda_wrapper_memcpy(out->tiles[0].data,
266-
s->cuda_out_buffer,
267-
out->tiles[0].data_len,
268-
CUDA_WRAPPER_MEMCPY_DEVICE_TO_HOST) != CUDA_WRAPPER_SUCCESS) {
269-
fprintf(stderr, "Memcpy failed: %s\n", cuda_wrapper_last_error_string());
270-
return NULL;
271-
}
263+
CHECK_CUDA(cuda_wrapper_memcpy(out->tiles[0].data, s->cuda_out_buffer,
264+
out->tiles[0].data_len,
265+
CUDA_WRAPPER_MEMCPY_DEVICE_TO_HOST),
266+
"Memcpy failed", return nullptr);
272267

273268
return out;
274269
}

0 commit comments

Comments
 (0)