kenba/opencl3

signal: 11, SIGSEGV: invalid memory reference

Closed this issue · 2 comments

The following code compiles and cargo test foo1 succeeds, but cargo test fails with:

process didn't exit successfully: /home/foo/target/debug/deps/opencl3-594da37a386292da (signal: 11, SIGSEGV: invalid memory reference)

Cargo.toml

[package]
name = "opencl3"
version = "0.1.0"
edition = "2021"
[dependencies]
opencl3 = "0.8.1"

main.rs

use opencl3::device::{get_all_devices, Device, CL_DEVICE_TYPE_GPU};
use opencl3::Result;

fn main() {
    println!("Hello, world!");
}

fn bar() -> Result<Device> {
    let device_id = *get_all_devices(CL_DEVICE_TYPE_GPU)?
        .first()
        .expect("no GPU found in platform");
    Ok(Device::new(device_id))
}

#[cfg(test)]
mod tests {
    use crate::bar;

    #[test]
    fn foo1() {
        bar().expect("the unexpected");
    }

    #[test]
    fn foo2() {
        bar().expect("the unexpected");
    }
}
kenba commented

Do you also get the fault when running the tests in single-threaded mode?
I.e.:

cargo test -- --test-threads=1

Yes! well done. Single-threaded mode fixes both the test case above, and the project where I encountered the issue in the first instance.