0

I've been writing a ray tracer using SYCL for a few weeks but I'm now facing a memory corruption issue and I really can't find where it's coming from.

I'm working on Windows 11 22H2 using the Intel oneAPI Base Toolkit and Visual Studio Community 2022 17.7.6.

On Windows, the output image is visibly broken.

On Ubuntu 20.04 (using the oenAPI Base Toolkit 2023.2.1), the output image looks fine but I assume the corruption is still present as it (almost always) crashes my Intel graphics driver when executing the code on the GPU using the gpu_selector_v (laptop, integrated Iris Xe). On the CPU on Ubuntu, the output image is normal, there doesn't seem to be any corruption issue (it's probably still there, just not showing).

On Ubuntu, I tried using valgrind to monitor the application on the CPU but it couldn't find any memory read/write violation. No errors were reported.

On Windows, DrMemory (valgrind equivalent) crashes (pastebin of the crash here) when executing the code and so doesn't report the source of the error.

Broken output on Windows

This corruption issue only arises when compiling in Release mode with optimizations on (/02 on Visual Studio). There seems to be no issues when in Debug mode or Release with optimizations disabled.

I managed to narrow the issue down to a single line of code in render_kernel.cpp:104 called from render_kernel.cpp:60 :

bool RenderKernel::intersect_scene(const Ray ray, HitInfo& closest_hit_info) const
{
    float closest_intersection_distance = -1.0f;
    bool inter_found = false;

    for (int i = 0; i < m_triangle_buffer_access.size(); i++)
    {
        const Triangle& triangle = m_triangle_buffer_access[i];

        HitInfo hit_info;
        if (triangle.intersect(ray, hit_info))
        {
            if (hit_info.t < closest_intersection_distance || !inter_found)
            {
                closest_intersection_distance = hit_info.t;
                
                ///////////
                closest_hit_info = hit_info; //Problematic line
                ///////////

                inter_found = true;
            }
        }
    }

    return inter_found;
}

On the image above, even the red background has artifacts. If you comment the line that assigns the intersection information to the output 'closest_hit_info' argument (line 18 in the snippet above) you obviously can't see the triangle anymore because the hit information is not updated but the red background also isn't full of artifacts anymore.

Reducing the number of bounces below 4 (render_kernel.h) also makes the issue go away. 4 or 5 bounces always show the artifacts in the output image whereas 3 or less bounces don't show any issue. This makes little to no sense as the scene doesn't even have enough geometry for bounces to happen so the execution should be the same with 2 or more bounces.

The full code base can be found in this repo, on the branch "MinimalCorruption". I tried to make it as minimal as possible.

If more details is needed about my system / installation, feel free to ask.

EDIT (11/14/2023): The issue is being tracked on the Intel forum.

EDIT (01/18/2024): Intel replied to my post on their forum and it seems like this is a compiler issue.

4
  • Generally, as long as your minimal, reproducible example needs to be linked from GitHub, it is not minimal enough for StackOverflow. The question should be self-contained, i.e. any links can only be supplementary. See e.g. Is showing a link to GitHub source code acceptable? and Is it okay to post Pastebin links if a critical portion of the question, for example a log file, is too long to post on Stack Overflow?. Commented Nov 3, 2023 at 11:55
  • @paleonix Unfortunately I'm not sure how to make the code any shorter while still having the issue reproducible. Commented Nov 3, 2023 at 12:02
  • I've not run your code myself, but two things stand out from a brief look: 1. Your frame_buffer_access should be read_write (you += final_colour). 2. I think you're using get_host_access() incorrectly - I believe it returns a host accessor that you should use. Commented Nov 9, 2023 at 14:11
  • @hjab This sounded like a potential issue but after fixing it, the artifacts are still there so it looks like this isn't the issue. Commented Nov 14, 2023 at 17:29

2 Answers 2

0

Have you tried to run on CPU with a pure C++ library implementation like AdaptiveCpp? Then you should be able to use the usual C++ CPU debugging tools like UBsan, ThreadSanitizer, Valgrind, whatever.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried removing SYCL entirely from the project, using std::vector<> and other pure C++ constructs instead of the SYCL ones and the code executes just fine, there are no artifacts. Valgrind also detects no memory issues on the pure C++ code.
Another option is running on NVIDIA GPU (with either AdaptiveCpp or oneAPI) and using NVIDIA's compute-sanitizer.
0

Intel replied to my post on their forum and it seems like the issue wasn't related to my code but rather to a bug in the compiler.

They're working on the issue internally.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.