Skip to content

[bug] Use GPUDEBUG macro instead of raw printf for kernel error message#265

Closed
PrasoonMishra wants to merge 1 commit into
fangq:masterfrom
PrasoonMishra:fix/gpudebug-kernel-printf
Closed

[bug] Use GPUDEBUG macro instead of raw printf for kernel error message#265
PrasoonMishra wants to merge 1 commit into
fangq:masterfrom
PrasoonMishra:fix/gpudebug-kernel-printf

Conversation

@PrasoonMishra

Copy link
Copy Markdown

The raw printf in the "should never happen" branch is compiled into the kernel even in release builds, increasing register pressure. Since MCX is register-limited, replacing it with GPUDEBUG (a no-op unless MCX_DEBUG is defined) frees registers and improves occupancy, giving ~2.5% speedup in release mode on AMD gf90a.

@fangq

fangq commented Jun 25, 2026

Copy link
Copy Markdown
Owner

use printf for printing "should never happen" is by design. this is a critical message that must be printed, if ever happens, regardless if the binary was compiled in debug mode or not.

@fangq fangq closed this Jun 25, 2026
@PrasoonMishra

Copy link
Copy Markdown
Author

@fangq
Thanks, that makes sense.

If above design is by choice, then I would like to flag for consistency issue between this and OpenCL port. The OpenCL port handles this same check differently. There it's gated behind GPUDEBUG, so in a normal build it's compiled out and never prints. ( mcx_core.cl Line: 3289 )

if ((GPU_PARAM(gcfg, debuglevel) & MCX_DEBUG_MOVE_ONLY) &
        (mediaid == 0 || idx1d == OUTSIDE_VOLUME_MIN || idx1d == OUTSIDE_VOLUME_MAX)) {
    GPUDEBUG(("ERROR: should never happen! mediaid=%d idx1d=%X\n", mediaid, idx1d));
    return;
}

As a result, the two ports currently diverge in behavior for the same condition. It would be great if they could be aligned so both ports handle this case consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants