diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/cnn_test.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/cnn_test.cc b/tools/cnn_test.cc index fa4394f..59f1d22 100644 --- a/tools/cnn_test.cc +++ b/tools/cnn_test.cc @@ -43,6 +43,7 @@ struct Args { bool output_png = true; // Default to PNG const char* save_intermediates = nullptr; int num_layers = 3; // Default to 3 layers + bool debug_hex = false; // Print first 8 pixels as hex }; // Parse command-line arguments @@ -80,6 +81,8 @@ static bool parse_args(int argc, char** argv, Args* args) { fprintf(stderr, "Error: layers must be in range [1, 10]\n"); return false; } + } else if (strcmp(argv[i], "--debug-hex") == 0) { + args->debug_hex = true; } else if (strcmp(argv[i], "--help") == 0) { return false; } else { @@ -99,6 +102,7 @@ static void print_usage(const char* prog) { fprintf(stderr, " --format ppm|png Output format (default: png)\n"); fprintf(stderr, " --layers N Number of CNN layers (1-10, default: 3)\n"); fprintf(stderr, " --save-intermediates DIR Save intermediate layers to directory\n"); + fprintf(stderr, " --debug-hex Print first 8 pixels as hex (debug)\n"); fprintf(stderr, " --help Show this help\n"); } @@ -437,6 +441,18 @@ int main(int argc, char** argv) { printf("Reading pixels from GPU...\n"); std::vector<uint8_t> pixels = rt.read_pixels(); + // Debug: print first 8 pixels as hex + if (args.debug_hex && !pixels.empty()) { + printf("First 8 pixels (BGRA hex):\n"); + for (int i = 0; i < 8 && i < width * height; ++i) { + const uint8_t b = pixels[i * 4 + 0]; + const uint8_t g = pixels[i * 4 + 1]; + const uint8_t r = pixels[i * 4 + 2]; + const uint8_t a = pixels[i * 4 + 3]; + printf(" [%d] 0x%02X%02X%02X%02X (RGBA)\n", i, r, g, b, a); + } + } + if (pixels.empty()) { fprintf(stderr, "Error: GPU readback failed\n"); wgpuTextureViewRelease(intermediate_views[0]); @@ -513,6 +529,18 @@ int main(int argc, char** argv) { std::vector<uint8_t> pixels = texture_readback_fp16_to_u8( device, queue, intermediate_textures[dst_idx], width, height); + // Debug: print first 8 pixels as hex + if (args.debug_hex && !pixels.empty()) { + printf("Layer %d first 8 pixels (BGRA hex):\n", layer); + for (int i = 0; i < 8 && i < width * height; ++i) { + const uint8_t b = pixels[i * 4 + 0]; + const uint8_t g = pixels[i * 4 + 1]; + const uint8_t r = pixels[i * 4 + 2]; + const uint8_t a = pixels[i * 4 + 3]; + printf(" [%d] 0x%02X%02X%02X%02X (RGBA)\n", i, r, g, b, a); + } + } + if (!pixels.empty()) { save_png(layer_path, pixels, width, height); } else { |
