cogciprocate / ocl

OpenCL for Rust
Other
721 stars 75 forks source link

Result in example file change when removing assert_eq!() #213

Closed veryhumanprogrammer closed 11 months ago

veryhumanprogrammer commented 1 year ago

I noticed that removing the assert_eq!() in the basics.rs example on line 80 caused the printed values to change. Not sure if this is intended, but it doesn't seem like it. I'm quite new to Rust so maybe I missed something, but I am unable to explain why this happens.

This is the part of the code in basic.rs I mean

    for idx in 0..WORK_SIZE {
        if idx < RESULTS_TO_PRINT {
            println!("source[{idx}]: {:.03}, \t coeff: {}, \tresult[{idx}]: {}",
            vec_source[idx], COEFF, results[idx], idx = idx);
        }
        assert_eq!(vec_source[idx] * COEFF, vec_result[idx]);
    }

If I change it to this, the printed values change

    for idx in 0..WORK_SIZE {
        if idx < RESULTS_TO_PRINT {
            println!("source[{idx}]: {:.03}, \t coeff: {}, \tresult[{idx}]: {}",
            vec_source[idx], COEFF, results[idx], idx = idx);
        }
    }

However, if I change it to this it doesn't change

    for idx in 0..WORK_SIZE {
        if idx < RESULTS_TO_PRINT {
            println!("source[{idx}]: {:.03}, \t coeff: {}, \tresult[{idx}]: {}",
            vec_source[idx], COEFF, results[idx], idx = idx);
        }
        let test = vec_source[0] * COEFF;
    }

Normal printed values:

image Altered printed values:

image

The line of code I'm talking about:

https://github.com/cogciprocate/ocl/blob/f495254064da566de1195a02ef399f6f2a054c11/ocl/examples/basics.rs#L80

c0gent commented 1 year ago

Very interesting. Thanks for reporting. We'll see if anyone else experiences this.

c0gent commented 11 months ago

I can't reproduce.

Still having this issue?