Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions core/include/internal/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class GPU {

for (uint32_t i = 0; i < info->messageCount; ++i) {
const auto& msg = info->messages[i];
IMG2NUM_LOG_INFO(
IMG2NUM_LOG_ERROR(
"Shader Error [{}] Line {}:{} - {}",
msg.type == wgpu::CompilationMessageType::Error ? "ERR" : "WARN",
msg.lineNum, msg.linePos,
Expand All @@ -149,15 +149,15 @@ class GPU {
instance = wgpu::CreateInstance(&instanceDesc);

if (!instance) {
IMG2NUM_LOG_INFO("Fatal: WebGPU instance creation failed. Falling back to CPU.");
IMG2NUM_LOG_WARN("Fatal: WebGPU instance creation failed. Falling back to CPU.");
cleanup();
return;
}

// ---------------------------------------------------------
// 1. Get Adapter
// ---------------------------------------------------------
IMG2NUM_LOG_INFO("Requesting Adapter...");
IMG2NUM_LOG_DEBUG("Requesting Adapter...");
adapter_ready = false;

instance.RequestAdapter(
Expand All @@ -168,7 +168,7 @@ class GPU {
adapter = std::move(a);
IMG2NUM_LOG_INFO("Adapter Acquired");
} else {
IMG2NUM_LOG_INFO(
IMG2NUM_LOG_WARN(
"Adapter Failed: {}", std::string_view(msg.data ? msg.data : "", msg.length)
);
}
Expand All @@ -185,21 +185,21 @@ class GPU {
}

if (!adapter) {
IMG2NUM_LOG_INFO("Fatal: Could not get WebGPU Adapter. Falling back to CPU.");
IMG2NUM_LOG_WARN("Fatal: Could not get WebGPU Adapter. Falling back to CPU.");
cleanup();
return;
}
if (wgpu::AdapterInfo info; adapter.GetInfo(&info) != wgpu::Status::Success ||
info.backendType == wgpu::BackendType::Null) {
IMG2NUM_LOG_INFO("No usable WebGPU adapter found. Falling back to CPU.");
IMG2NUM_LOG_WARN("No usable WebGPU adapter found. Falling back to CPU.");
cleanup();
return;
}

// ---------------------------------------------------------
// 2. Get Device
// ---------------------------------------------------------
IMG2NUM_LOG_INFO("Requesting Device...");
IMG2NUM_LOG_DEBUG("Requesting Device...");
device_ready = false;

wgpu::DeviceDescriptor deviceDesc = {};
Expand All @@ -210,7 +210,7 @@ class GPU {
: "Unknown Error (Null message)";

// 2. Print it safely
IMG2NUM_LOG_INFO(
IMG2NUM_LOG_ERROR(
"\n[WEBGPU FATAL ERROR] Type: {} | Msg: {}\n", static_cast<uint32_t>(type), err_str
);
});
Expand All @@ -224,7 +224,7 @@ class GPU {
if (reason == wgpu::DeviceLostReason::CallbackCancelled) {
return;
}
IMG2NUM_LOG_INFO(
IMG2NUM_LOG_ERROR(
"[DEVICE LOST] Reason: {} Msg: {}", static_cast<int>(reason), err_msg
);
}
Expand All @@ -239,8 +239,8 @@ class GPU {
// Copy the adapter's physical limits over to your requested limits
requiredLimits = supportedLimits;

IMG2NUM_LOG_INFO("maxBufferSize: {}", requiredLimits.maxBufferSize);
IMG2NUM_LOG_INFO(
IMG2NUM_LOG_DEBUG("maxBufferSize: {}", requiredLimits.maxBufferSize);
IMG2NUM_LOG_DEBUG(
"maxStorageBufferBindingSize: {}", requiredLimits.maxStorageBufferBindingSize
);

Expand All @@ -255,7 +255,7 @@ class GPU {
device = std::move(d);
IMG2NUM_LOG_INFO("Device Acquired");
} else {
IMG2NUM_LOG_INFO(
IMG2NUM_LOG_WARN(
"Device Failed: {}", msg.data && msg.length > 0
? std::string(msg.data, msg.length)
: "Unknown error"
Expand All @@ -274,13 +274,13 @@ class GPU {
}

if (!device) {
IMG2NUM_LOG_INFO("Fatal: Could not get WebGPU Device. Falling back to CPU.");
IMG2NUM_LOG_WARN("Fatal: Could not get WebGPU Device. Falling back to CPU.");
cleanup();
return;
}

if (!validate_device()) {
IMG2NUM_LOG_INFO("Fatal: Could not get WebGPU Device. Falling back to CPU.");
IMG2NUM_LOG_WARN("Fatal: Could not get WebGPU Device. Falling back to CPU.");
cleanup();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion core/include/internal/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace img2num::third_party_wrappers {
// Lazily-created library logger.
inline spdlog::logger& logger() {
static const auto instance = [] {
auto l = spdlog::stdout_color_mt("img2num");
auto l = spdlog::stderr_color_mt("img2num");
// Sync runtime filtering with compile-time stripping
l->set_level(static_cast<spdlog::level::level_enum>(SPDLOG_ACTIVE_LEVEL));
return l;
Expand Down
12 changes: 6 additions & 6 deletions core/src/internal/bilateral_filter_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ void bilateral_filter_gpu(
const uint32_t h = static_cast<uint32_t>(height);
constexpr uint32_t bpp = 4; // RGBA8 = 4 bytes per pixel

IMG2NUM_LOG_INFO("begin wgpu portion");
IMG2NUM_LOG_DEBUG("begin wgpu portion");

// 1. Create textures (RAII — destroyed automatically on scope exit)
gpu::Texture inputTexture(
w, h, wgpu::TextureFormat::RGBA8Unorm,
wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::CopyDst
);

IMG2NUM_LOG_INFO("upload texture");
IMG2NUM_LOG_DEBUG("upload texture");
inputTexture.write(image, bpp * width * height, bpp);

IMG2NUM_LOG_INFO("create output texture");
IMG2NUM_LOG_DEBUG("create output texture");
gpu::Texture outputTexture(
w, h, wgpu::TextureFormat::RGBA8Unorm,
wgpu::TextureUsage::StorageBinding | wgpu::TextureUsage::CopySrc
Expand All @@ -83,7 +83,7 @@ void bilateral_filter_gpu(
wgpu::TextureUsage::StorageBinding | wgpu::TextureUsage::TextureBinding
);

IMG2NUM_LOG_INFO("create buffer");
IMG2NUM_LOG_DEBUG("create buffer");
// 2. Create uniform buffer with filter parameters
gpu::Buffer<FilterParams> paramBuffer(
1, wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopyDst
Expand Down Expand Up @@ -169,12 +169,12 @@ void bilateral_filter_gpu(

wgpu::CommandBuffer commands = encoder.Finish();
GPU::getClassInstance().get_queue().Submit(1, &commands);
IMG2NUM_LOG_INFO("queue submit");
IMG2NUM_LOG_DEBUG("queue submit");

// 6. Readback — handles staging buffer, MapAsync, alignment stripping automatically
std::vector<uint8_t> result = outputTexture.read(bpp);
std::memcpy(image, result.data(), result.size());
IMG2NUM_LOG_INFO("done memcpy");
IMG2NUM_LOG_DEBUG("done memcpy");

// All textures and buffers are destroyed automatically by RAII destructors
#if defined(__EMSCRIPTEN__)
Expand Down
16 changes: 8 additions & 8 deletions core/src/internal/kmeans_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void kmeans_gpu(
}
}

IMG2NUM_LOG_INFO("starting");
IMG2NUM_LOG_DEBUG("starting");

// Step 2: Initialize centroids via K-Means++
switch (color_space) {
Expand All @@ -260,7 +260,7 @@ void kmeans_gpu(
break;
}

IMG2NUM_LOG_INFO("kmeans++ init done");
IMG2NUM_LOG_DEBUG("kmeans++ init done");

// =========================================================================
// GPU resource setup (previously in setup() function)
Expand Down Expand Up @@ -377,7 +377,7 @@ void kmeans_gpu(
// =========================================================================
// Main K-Means loop — all iterations batched into one submission
// =========================================================================
IMG2NUM_LOG_INFO("start iterations");
IMG2NUM_LOG_DEBUG("start iterations");
uint32_t wgX = gpu::workgroup_count(w);
uint32_t wgY = gpu::workgroup_count(h);

Expand All @@ -388,17 +388,17 @@ void kmeans_gpu(
}
wgpu::CommandBuffer commands = encoder.Finish();
GPU::getClassInstance().get_queue().Submit(1, &commands);
IMG2NUM_LOG_INFO("done iterations");
IMG2NUM_LOG_DEBUG("done iterations");

// =========================================================================
// Readback — alignment stripping handled automatically
// =========================================================================

// Read labels (RGBA32Uint, 16 bytes/pixel — extract R channel as label)
IMG2NUM_LOG_INFO("read out");
IMG2NUM_LOG_DEBUG("read out");
std::vector<uint8_t> labelData = labelTexture.read(bpp);

IMG2NUM_LOG_INFO("mapping labels");
IMG2NUM_LOG_DEBUG("mapping labels");
for (int32_t i = 0; i < num_pixels; ++i) {
uint32_t r = 0;
std::memcpy(&r, &labelData[i * bpp], sizeof(uint32_t));
Expand All @@ -409,7 +409,7 @@ void kmeans_gpu(
std::vector<uint8_t> centroidData = centroidTexture.read(bpp);
const float* centroidFloats = reinterpret_cast<const float*>(centroidData.data());

IMG2NUM_LOG_INFO("mapping centroids");
IMG2NUM_LOG_DEBUG("mapping centroids");
for (int i = 0; i < k; i++) {
float cr = centroidFloats[i * 4];
float cg = centroidFloats[i * 4 + 1];
Expand Down Expand Up @@ -445,7 +445,7 @@ void kmeans_gpu(
}

// Write labels to out_labels
IMG2NUM_LOG_INFO("copying labels out");
IMG2NUM_LOG_DEBUG("copying labels out");
std::memcpy(out_labels, labels.data(), labels.size() * sizeof(int32_t));

#if defined(__EMSCRIPTEN__)
Expand Down
Loading