Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_supported_image_formats fails on Mac OS X #67

Closed
michael-p opened this issue Apr 23, 2017 · 9 comments
Closed

get_supported_image_formats fails on Mac OS X #67

michael-p opened this issue Apr 23, 2017 · 9 comments
Labels

Comments

@michael-p
Copy link
Contributor

michael-p commented Apr 23, 2017

core::get_supported_image_formats fails on OSX by returning

Image Formats: Err(
    Error converting to 'ImageChannelOrder'.
).

The reason is that some of the returned values for channel order and datatype are completely weird. On the CPU device I get:

Found 28 image formats
...
Ch.order: 4284, data type: 4317
Ch.order: 4277, data type: 268435464
Ch.order: 4277, data type: 4312
...
Ch.order: 4284, data type: 4307
Ch.order: 268435462, data type: 4306
Ch.order: 4273, data type: 4306
Ch.order: 4279, data type: 4306
Ch.order: 268435463, data type: 4306
Ch.order: 4278, data type: 4306
...

On the GPU device:

Found 84 image formats
...
Ch.order: 4279, data type: 4306
Ch.order: 268435474, data type: 4306
Ch.order: 4272, data type: 4304
...

The values were determined using this small C program (posting it here because maybe I made a mistake somewhere?)

#include <stdio.h>
#include <sys/types.h>

#include <OpenCL/cl.h>

#define CHECK_ERR { \
    if(err < 0) { \
        perror("OPenCL error"); \
        exit(1); \
    } \
}

int main() {
    cl_int err;

    cl_platform_id platform;
    err = clGetPlatformIDs(1, &platform, NULL);
    CHECK_ERR

    cl_device_id device;
    err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &device, NULL);
    CHECK_ERR

    cl_context context;
    context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
    CHECK_ERR

    cl_uint num_img_formats = 0;
    cl_image_format formats[100];
    err = clGetSupportedImageFormats(context,
                                     CL_MEM_READ_WRITE,
                                     CL_MEM_OBJECT_IMAGE2D,
                                     sizeof(formats) / sizeof(formats[0]),
                                     formats,
                                     &num_img_formats);
    CHECK_ERR

    printf("Found %d image formats\n", num_img_formats);

    for (int i=0; i<num_img_formats; ++i) {
        printf("Ch.order: %d, data type: %d\n",
               formats[i].image_channel_order,
               formats[i].image_channel_data_type);
    }

    clReleaseContext(context);
}

Doing the same thing using cl-sys yields the same results.

I could not find any of those strange values in Apple's OpenCL headers.

@c0gent
Copy link
Member

c0gent commented Apr 23, 2017

Ok looks like there are some Apple-specific image channel orders that I need to include in the definition for ImageChannelOrder. I'll look through the relevant extension header file and add them :)

@c0gent c0gent added the wontfix label Apr 23, 2017
@c0gent
Copy link
Member

c0gent commented Apr 23, 2017

I failed to read the last line of your post. I'm in the same boat. Those image channel orderings are unspecified. This will be a wontfix until we can find some sort of definition for those values.

Thanks for your investigative work.

@michael-p
Copy link
Contributor Author

Or maybe in ImageFormat::list_from_raw just ignore the unknown formats instead of causing the whole call to fail completely?

@c0gent
Copy link
Member

c0gent commented Apr 24, 2017

I was thinking about creating an additional enum variant, something like ImageChannelOrder::Unknown(usize) which could contain unexpected image channel orderings but I just can't think of any reason why it would be useful. How is it that an unspecified image ordering of all things could be somehow useful.

I'm eager to be convinced. Until then I think it's only correct that it remains an error.

@michael-p
Copy link
Contributor Author

Yeah I also cannot think of any reasons why one might want to know about an unspecified image format. But I would prefer core::get_supported_image_formats to simply not return those instead of failing completely. As it is now, this function (and hence several of the examples) panic just because the device has some additional capabilities that are actually not used at all.

@c0gent
Copy link
Member

c0gent commented Apr 25, 2017

Ok, I'll add an ImageChannelOrder::Unknown(...) or ::Unsupported(...) or something.

@c0gent
Copy link
Member

c0gent commented Apr 28, 2017

cogciprocate/ocl-core@6ce4f27 and 5c0fde4 should take care of it.

Image formats returned from info functions are now individually wrapped in a Result<ImageFormat, ImageFormatParseError>. Let me know if that works ok. If so please paste some of the output of the img_formats.rs so that I can see how it looks :)

@michael-p
Copy link
Contributor Author

Works great, thank you very much for your work!
Here's the abbreviated output of img_formats.rs:

Platform [0]: Apple
Device [0]: Intel Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Image Formats: [
    ...
    Ok(
        ImageFormat {
            channel_order: Argb,
            channel_data_type: UnormInt8
        }
    ),
    Err(
        unknown image channel ordering: '268435463'
    ),
    Ok(
        ImageFormat {
            channel_order: Bgra,
            channel_data_type: UnormInt8
        }
    ),
    ...
].
Platform [0]: Apple
Device [1]: Intel Inc. Intel(R) Iris(TM) Graphics 6100
Image Formats: [
    ...
    Ok(
        ImageFormat {
            channel_order: Argb,
            channel_data_type: UnormInt8
        }
    ),
    Err(
        unknown image channel ordering: '268435474'
    ),
    Ok(
        ImageFormat {
            channel_order: R,
            channel_data_type: SnormInt8
        }
    ),
    ...
].

@c0gent
Copy link
Member

c0gent commented May 3, 2017

Excellent :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants