m4rs-mt / ILGPU

ILGPU JIT Compiler for high-performance .Net GPU programs
http://www.ilgpu.net
Other
1.35k stars 116 forks source link

Fixed OpenCL printf newline output. #1182

Closed MoFtZ closed 5 months ago

MoFtZ commented 5 months ago

The Interop.WriteLine output on Windows OpenCL was always less than desirable - showing "\r\n" in the output instead of a newline. We suspected this was an OpenCL driver issue.

image

This PR fixes the output by addressing two issues.

The first issue is that escaping \ was the last step, which incorrectly double-escaped all previous escapes.

The second issue is that \r\n is a Windows convention, but C-printf normally uses just \n. The underlying C-printf implementation then converts \n to \r\n on Windows devices. To handle this, we use Environment.NewLine to deal with whether we are running on Windows or Unix. Without converting \r\n as a single translation, my OpenCL implementation would translate \r to "r", and then \n to a newline.

The fixed output now looks correct: image