Skip to content

spirv: OpenCL printf support #24321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

ivanstepanovftw
Copy link

@ivanstepanovftw ivanstepanovftw commented Jul 2, 2025

I want to have std.debug.printf() implemented for GPGPU, because it lowers entry point for newcomers, and this feature allows to catch bugs faster (like I had with signed_integer - 0).

To test this PR you need to clone zig-spirv-test-executor in root dir and run:

./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib
./stage4/bin/zig build --build-file ./zig-spirv-test-executor/build.zig
export RUSTICL_ENABLE=llvmpipe
./stage4/bin/zig test ./test/behavior/asm.zig \
    --test-runner ./zig-spirv-test-executor/src/test_runner.zig \
    -target spirv64-opencl-none \
    -mcpu generic+int64+float64+float16 \
    -fno-llvm \
    --test-cmd ./zig-spirv-test-executor/zig-out/bin/zig-spirv-test-executor \
    --test-cmd --platform \
    --test-cmd rusticl \
    --test-cmd-bin

Better to review per commit.

@ivanstepanovftw

This comment was marked as outdated.

@alichraghi
Copy link
Contributor

I suggest you to not integrate it with std.debug.print and instead have std.gpu.printf which doesn't try to integrate with any zig formatting and is just a simple call to OpenCL's printf.

@ivanstepanovftw

This comment was marked as outdated.

Comment on lines +385 to +395
.OpTypeArray => blk: {
// TODO: The length of an OpTypeArray is determined by a constant (which may be a spec constant),
// and so some consideration must be taken when entering this in the type system.
return self.todo("process OpTypeArray", .{});
const element_type = try self.resolveRefId(operands[1].ref_id);
const length = try self.resolveRefId(operands[2].ref_id);
const result_id = self.spv.allocId();
try section.emit(self.spv.gpa, .OpTypeArray, .{
.id_result = result_id,
.element_type = element_type,
.length = length,
});
break :blk result_id;
Copy link
Author

@ivanstepanovftw ivanstepanovftw Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated change to the PR - I hoped to make better "string constants with c constraint" testing in tests/behavior/asm.zig. It does work though.

Copy link
Author

@ivanstepanovftw ivanstepanovftw Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I drop this commit since I am not trusted and no single test cover this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah it looks correct

Copy link
Contributor

@alichraghi alichraghi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few nitpicks that i can fix myself but otherwise LGTM. Hopefully we can switch to an std.format version later

@ivanstepanovftw

This comment was marked as outdated.

@ivanstepanovftw
Copy link
Author

Rebased.

@ivanstepanovftw
Copy link
Author

ivanstepanovftw commented Jul 22, 2025

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.

3 participants