ocl icon indicating copy to clipboard operation
ocl copied to clipboard

Context dropped while still referred to by Queue or Program, causing panics

Open aabizri opened this issue 6 years ago • 0 comments

When creating a ProQue for example, and making it go out of scope (and be dropped), the Context referred to by Queue or Program is dropped, making calls like Queue::context() or Program::info(ocl::core::ProgramInfo::Context) panic ! (tested on ocl 0.19)

Panic message example:

################################ OPENCL ERROR ############################### 

Error executing function: clRetainContext  

Status error code: CL_INVALID_CONTEXT (-34)  

Please visit the following url for more information: 

https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clRetainContext.html#errors  

############################################################################# 
', src/libcore/result.rs:1165:5
stack backtrace:
  [... omitted]
  15: core::result::Result<T,E>::unwrap
             at /rustc/96d07e0ac9f0c56b95a2561c6cedac0b23a5d2a3/src/libcore/result.rs:933
  16: ocl_core::types::abs::Context::from_raw_copied_ptr
             at /home/aabizri/.cargo/registry/src/github.com-1ecc6299db9ec823/ocl-core-0.11.2/src/types/abs.rs:475
  17: ocl_core::types::abs::CommandQueue::context::{{closure}}
             at /home/aabizri/.cargo/registry/src/github.com-1ecc6299db9ec823/ocl-core-0.11.2/src/types/abs.rs:605
  18: core::result::Result<T,E>::map
             at /rustc/96d07e0ac9f0c56b95a2561c6cedac0b23a5d2a3/src/libcore/result.rs:512
  19: ocl_core::types::abs::CommandQueue::context
             at /home/aabizri/.cargo/registry/src/github.com-1ecc6299db9ec823/ocl-core-0.11.2/src/types/abs.rs:605
  20: ocl::standard::queue::Queue::context
             at /home/aabizri/.cargo/registry/src/github.com-1ecc6299db9ec823/ocl-0.19.3/src/standard/queue.rs:68
  21: ocl_proque_drop_error::main
             at src/main.rs:19
  [... omitted]

Minimum example for replication (using Queue but I also tested with Program)

extern crate ocl;

const KERNEL_SRC: &str = r#"
__kernel void nothing() {}
"#;

fn create_queue() -> ocl::Queue {
    ocl::ProQue::builder()
        .src(KERNEL_SRC)
        .dims(1 << 20)
        .build()
        .unwrap()
        .queue()
        .clone()
}

fn main() {
    let queue = create_queue();
    queue.context();
}

Other example using Program: main.txt

My guess is that as raw pointers are used, the compiler doesn't keep track.

aabizri avatar Sep 22 '19 02:09 aabizri