forked from pyccel/pyccel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request fixes #48, by implementing a tiny wrapper for CUDA and a wrapper for non-CUDA functionalities only with external 'C'. **Commit Summary** - Implemented new header printer for CUDA. - Added CUDA wrapper assignment - Instead of wrapping all local headers, wrap only C functions with extern 'C' --------- Co-authored-by: EmilyBourne <[email protected]> Co-authored-by: bauom <[email protected]>
- Loading branch information
1 parent
02a2360
commit bd73514
Showing
7 changed files
with
143 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ Contributors | |
* Farouk Ech-Charef | ||
* Mustapha Belbiad | ||
* Varadarajan Rengaraj | ||
* Said Mazouz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# coding: utf-8 | ||
#------------------------------------------------------------------------------------------# | ||
# This file is part of Pyccel which is released under MIT License. See the LICENSE file or # | ||
# go to https://github.com/pyccel/pyccel/blob/master/LICENSE for full license details. # | ||
#------------------------------------------------------------------------------------------# | ||
""" | ||
Module describing the code-wrapping class : CudaToPythonWrapper | ||
which creates an interface exposing Cuda code to C. | ||
""" | ||
|
||
from pyccel.ast.bind_c import BindCModule | ||
from pyccel.errors.errors import Errors | ||
from pyccel.ast.bind_c import BindCVariable | ||
from .wrapper import Wrapper | ||
|
||
errors = Errors() | ||
|
||
class CudaToCWrapper(Wrapper): | ||
""" | ||
Class for creating a wrapper exposing Cuda code to C. | ||
While CUDA is typically compatible with C by default. | ||
this wrapper becomes necessary in scenarios where specific adaptations | ||
or modifications are required to ensure seamless integration with C. | ||
""" | ||
|
||
def _wrap_Module(self, expr): | ||
""" | ||
Create a Module which is compatible with C. | ||
Create a Module which provides an interface between C and the | ||
Module described by expr. | ||
Parameters | ||
---------- | ||
expr : pyccel.ast.core.Module | ||
The module to be wrapped. | ||
Returns | ||
------- | ||
pyccel.ast.core.BindCModule | ||
The C-compatible module. | ||
""" | ||
init_func = expr.init_func | ||
if expr.interfaces: | ||
errors.report("Interface wrapping is not yet supported for Cuda", | ||
severity='warning', symbol=expr) | ||
if expr.classes: | ||
errors.report("Class wrapping is not yet supported for Cuda", | ||
severity='warning', symbol=expr) | ||
|
||
variables = [self._wrap(v) for v in expr.variables] | ||
|
||
return BindCModule(expr.name, variables, expr.funcs, | ||
init_func=init_func, | ||
scope = expr.scope, | ||
original_module=expr) | ||
|
||
def _wrap_Variable(self, expr): | ||
""" | ||
Create all objects necessary to expose a module variable to C. | ||
Create and return the objects which must be printed in the wrapping | ||
module in order to expose the variable to C | ||
Parameters | ||
---------- | ||
expr : pyccel.ast.variables.Variable | ||
The module variable. | ||
Returns | ||
------- | ||
pyccel.ast.core.BindCVariable | ||
The C-compatible variable. which must be printed in | ||
the wrapping module to expose the variable. | ||
""" | ||
return expr.clone(expr.name, new_class = BindCVariable) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# pylint: disable=missing-function-docstring, missing-module-docstring | ||
import numpy as np | ||
|
||
g = np.float64(9.81) | ||
r0 = np.float32(1.0) | ||
rmin = 0.01 | ||
rmax = 1.0 | ||
|
||
skip_centre = True | ||
|
||
method = 3 | ||
|
||
tiny = np.int32(4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters