Giter Site home page Giter Site logo

Panic when no GPUs about ocl HOT 7 CLOSED

cogciprocate avatar cogciprocate commented on May 22, 2024
Panic when no GPUs

from ocl.

Comments (7)

jekirl avatar jekirl commented on May 22, 2024

This occurs whenever ocl::core:: get_device_ids does not receive CL_SUCCESS as a result of the ffi call to clGetDeviceIDs.

I see two options, either to change the return type to Result<Vec<Device>> or to replace the expect with unwrap_or(vec![])

from ocl.

c0gent avatar c0gent commented on May 22, 2024

I agree. Try out the device_result branch and let me know how that looks to you two.

from ocl.

c0gent avatar c0gent commented on May 22, 2024

@yongqli @J-e-k

I'm hesitant to add too many convenience functions but would the following be a useful Device method?:

    /// Returns a list of devices exactly as `::list` does but unwraps any
    /// error and returns an empty `Vec` in the event that the error is a
    /// `CL_DEVICE_NOT_FOUND` variant.
    ///
    /// This is a convenience function.
    ///
    ///
    /// ### Panics
    ///
    /// Panics upon any OpenCL error other than `CL_DEVICE_NOT_FOUND` or any
    /// other type of error.
    ///
    pub fn list_or_empty(platform: &Platform, device_types: Option<DeviceType>)
                -> Vec<Device> {
        match Device::list(platform, device_types) {
            Ok(vec) => vec,
            Err(err) => match err.status() {
                Some(s) => match s {
                    Status::CL_DEVICE_NOT_FOUND => Vec::with_capacity(0),
                    _ => panic!("{}", err),
                },
                None => panic!("{}", err),
            },
        }
    }

from ocl.

jekirl avatar jekirl commented on May 22, 2024

Thanks for the fast fix. I don't think list_or_empty is particularly necessary (for my use case at least). Using result as you did in #40 is 👍

from ocl.

c0gent avatar c0gent commented on May 22, 2024

Alright. If @yongqli is satisfied I'll merge and close this.

from ocl.

yongqli avatar yongqli commented on May 22, 2024

@c0gent Thanks, but I don't feel the convenience function is particularly necessary either.

from ocl.

c0gent avatar c0gent commented on May 22, 2024

Good enough. Thanks guys.

from ocl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.