Skip to content

Cython extension cimporting dpctl fails to compile in C #585

Closed

Description

@oleksandr-pavlyk

A simple Cython extension that involved cimport dpctl translated to C can not be compiled.

# File: a.pyx
# cython: language=c
# cython: language_level=3

cimport dpctl as c_dpctl
import dpctl

def foo(c_dpctl.SyclQueue q):
    return q.sycl_device.max_compute_unit

Then execute cythonize a.pyx to produce a.c. Compile the file using

gcc -fmax-errors=1 a.c -I$(python -c "import dpctl; print(dpctl.get_include())") -I$(python3-config --includes)

This results in a compilation error due to undefined type bool:

In file included from a.c:638:
/localdisk/repos/dpctl/dpctl/include/dpctl_sycl_device_interface.h:99:1: error: unknown type name ‘bool’
   99 | bool DPCTLDevice_IsAccelerator(__dpctl_keep const DPCTLSyclDeviceRef DRef);
      | ^~~~
compilation terminated due to -fmax-errors=1.

Activity

  1. oleksandr-pavlyk commented on Sep 13, 2021

    @oleksandr-pavlyk
    ContributorAuthor

    I suppose DPCTL-capi headers should define bool type when the compiler is not __cplusplus__.

  2. diptorupd commented on Sep 23, 2021

    @diptorupd
    Contributor

    @oleksandr-pavlyk can you try gcc -fmax-errors=1 a.c -I$(python -c "import dpctl; print(dpctl.get_include())") -I$(python3-config --includes) -std=c99. bool is in the C99 standard and we should not need anything extra unless we need older C standard support.

  3. oleksandr-pavlyk commented on Sep 23, 2021

    @oleksandr-pavlyk
    ContributorAuthor

    Using -std=c99 does not seem to help:

    (idp) [11:19:39 ansatnuc04 issue_c_cython_dpctl]$ gcc -fmax-errors=1 a.c -I$(python -c "import dpctl; print(dpctl.get_include())") -I$(python3-config --includes) -std=c99
    In file included from a.c:638:
    /localdisk/work/opavlyk/repos/dpctl/dpctl/include/dpctl_sycl_device_interface.h:99:1: error: unknown type name ‘bool’
       99 | bool DPCTLDevice_IsAccelerator(__dpctl_keep const DPCTLSyclDeviceRef DRef);
          | ^~~~
    compilation terminated due to -fmax-errors=1.
    

    The compiler is not old:

    (idp) [11:19:50 ansatnuc04 issue_c_cython_dpctl]$ gcc --version
    gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
    Copyright (C) 2019 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    By the way, it would be cool if dpctl provided __main__.py to enable generation of includes with -I$(python -m dpctl --includes).

  4. oleksandr-pavlyk commented on Sep 28, 2021

    @oleksandr-pavlyk
    ContributorAuthor

    Evidently, one needs to #include <stdbool.h>.

  5. added a commit that references this issue on Sep 28, 2021
    a8fa412
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions