|
| 1 | +# coding: utf-8 |
| 2 | +#------------------------------------------------------------------------------------------# |
| 3 | +# This file is part of Pyccel which is released under MIT License. See the LICENSE file or # |
| 4 | +# go to https://github.com/pyccel/pyccel/blob/master/LICENSE for full license details. # |
| 5 | +#------------------------------------------------------------------------------------------# |
| 6 | +""" |
| 7 | +Module describing the code-wrapping class : CudaToPythonWrapper |
| 8 | +which creates an interface exposing Cuda code to C. |
| 9 | +""" |
| 10 | + |
| 11 | +from pyccel.ast.bind_c import BindCModule |
| 12 | +from pyccel.errors.errors import Errors |
| 13 | +from pyccel.ast.bind_c import BindCVariable |
| 14 | +from .wrapper import Wrapper |
| 15 | + |
| 16 | +errors = Errors() |
| 17 | + |
| 18 | +class CudaToCWrapper(Wrapper): |
| 19 | + """ |
| 20 | + Class for creating a wrapper exposing Cuda code to C. |
| 21 | +
|
| 22 | + While CUDA is typically compatible with C by default. |
| 23 | + this wrapper becomes necessary in scenarios where specific adaptations |
| 24 | + or modifications are required to ensure seamless integration with C. |
| 25 | + """ |
| 26 | + |
| 27 | + def _wrap_Module(self, expr): |
| 28 | + """ |
| 29 | + Create a Module which is compatible with C. |
| 30 | +
|
| 31 | + Create a Module which provides an interface between C and the |
| 32 | + Module described by expr. |
| 33 | +
|
| 34 | + Parameters |
| 35 | + ---------- |
| 36 | + expr : pyccel.ast.core.Module |
| 37 | + The module to be wrapped. |
| 38 | +
|
| 39 | + Returns |
| 40 | + ------- |
| 41 | + pyccel.ast.core.BindCModule |
| 42 | + The C-compatible module. |
| 43 | + """ |
| 44 | + init_func = expr.init_func |
| 45 | + if expr.interfaces: |
| 46 | + errors.report("Interface wrapping is not yet supported for Cuda", |
| 47 | + severity='warning', symbol=expr) |
| 48 | + if expr.classes: |
| 49 | + errors.report("Class wrapping is not yet supported for Cuda", |
| 50 | + severity='warning', symbol=expr) |
| 51 | + |
| 52 | + variables = [self._wrap(v) for v in expr.variables] |
| 53 | + |
| 54 | + return BindCModule(expr.name, variables, expr.funcs, |
| 55 | + init_func=init_func, |
| 56 | + scope = expr.scope, |
| 57 | + original_module=expr) |
| 58 | + |
| 59 | + def _wrap_Variable(self, expr): |
| 60 | + """ |
| 61 | + Create all objects necessary to expose a module variable to C. |
| 62 | +
|
| 63 | + Create and return the objects which must be printed in the wrapping |
| 64 | + module in order to expose the variable to C |
| 65 | +
|
| 66 | + Parameters |
| 67 | + ---------- |
| 68 | + expr : pyccel.ast.variables.Variable |
| 69 | + The module variable. |
| 70 | +
|
| 71 | + Returns |
| 72 | + ------- |
| 73 | + pyccel.ast.core.BindCVariable |
| 74 | + The C-compatible variable. which must be printed in |
| 75 | + the wrapping module to expose the variable. |
| 76 | + """ |
| 77 | + return expr.clone(expr.name, new_class = BindCVariable) |
| 78 | + |
0 commit comments