Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
fd31ce64
Commit
fd31ce64
authored
4 months ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
move kernel wrapper creation to the module builder
parent
4dcb81ac
No related branches found
No related tags found
1 merge request
!445
Object-Oriented CPU JIT API and Prototype Implementation
Pipeline
#72944
passed
4 months ago
Stage: Code Quality
Stage: Unit Tests
Stage: legacy_test
Stage: docs
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencils/jit/cpu/cpujit.py
+5
-14
5 additions, 14 deletions
src/pystencils/jit/cpu/cpujit.py
src/pystencils/jit/cpu/cpujit_pybind11.py
+18
-0
18 additions, 0 deletions
src/pystencils/jit/cpu/cpujit_pybind11.py
with
23 additions
and
14 deletions
src/pystencils/jit/cpu/cpujit.py
+
5
−
14
View file @
fd31ce64
...
...
@@ -104,7 +104,7 @@ class CpuJit(JitBase):
def
strict_scalar_types
(
self
,
v
:
bool
):
self
.
_strict_scalar_types
=
v
def
compile
(
self
,
kernel
:
Kernel
)
->
CpuJit
KernelWrapper
:
def
compile
(
self
,
kernel
:
Kernel
)
->
KernelWrapper
:
# Get the Code
module_name
=
f
"
{
kernel
.
function_name
}
_jit
"
cpp_code
=
self
.
_ext_module_builder
(
kernel
,
module_name
)
...
...
@@ -149,7 +149,7 @@ class CpuJit(JitBase):
module_dir
=
Path
(
tmpdir
)
module
=
compile_and_load
(
module_dir
)
return
CpuJitKernelW
rapper
(
kernel
,
module
)
return
self
.
_ext_module_builder
.
get_w
rapper
(
kernel
,
module
)
def
_compile_extension_module
(
self
,
src_file
:
Path
,
libfile
:
Path
):
args
=
(
...
...
@@ -179,18 +179,6 @@ class CpuJit(JitBase):
return
mod
class
CpuJitKernelWrapper
(
KernelWrapper
):
def
__init__
(
self
,
kernel
:
Kernel
,
jit_module
:
ModuleType
):
super
().
__init__
(
kernel
)
self
.
_module
=
jit_module
self
.
_check_params
=
getattr
(
jit_module
,
"
check_params
"
)
self
.
_invoke
=
getattr
(
jit_module
,
"
invoke
"
)
def
__call__
(
self
,
**
kwargs
)
->
None
:
self
.
_check_params
(
**
kwargs
)
return
self
.
_invoke
(
**
kwargs
)
class
ExtensionModuleBuilderBase
(
ABC
):
@staticmethod
@abstractmethod
...
...
@@ -198,3 +186,6 @@ class ExtensionModuleBuilderBase(ABC):
@abstractmethod
def
__call__
(
self
,
kernel
:
Kernel
,
module_name
:
str
)
->
str
:
...
@abstractmethod
def
get_wrapper
(
self
,
kernel
:
Kernel
,
extension_module
:
ModuleType
)
->
KernelWrapper
:
...
This diff is collapsed.
Click to expand it.
src/pystencils/jit/cpu/cpujit_pybind11.py
+
18
−
0
View file @
fd31ce64
from
__future__
import
annotations
from
types
import
ModuleType
from
typing
import
Sequence
,
cast
from
pathlib
import
Path
from
textwrap
import
indent
from
pystencils.jit.jit
import
KernelWrapper
from
...types
import
PsPointerType
,
PsType
from
...field
import
Field
from
...sympyextensions
import
DynamicType
...
...
@@ -69,6 +72,9 @@ class Pybind11KernelModuleBuilder(ExtensionModuleBuilderBase):
kernel_definition
=
kernel_def
,
)
return
code_str
def
get_wrapper
(
self
,
kernel
:
Kernel
,
extension_module
:
ModuleType
)
->
KernelWrapper
:
return
Pybind11KernelWrapper
(
kernel
,
extension_module
)
def
_get_kernel_definition
(
self
,
kernel
:
Kernel
)
->
str
:
from
...backend.emission
import
CAstPrinter
...
...
@@ -158,3 +164,15 @@ class Pybind11KernelModuleBuilder(ExtensionModuleBuilderBase):
self
.
_extract_stride
(
param
,
cast
(
FieldStride
,
stride_props
.
pop
()))
else
:
self
.
_add_scalar_param
(
param
)
class
Pybind11KernelWrapper
(
KernelWrapper
):
def
__init__
(
self
,
kernel
:
Kernel
,
jit_module
:
ModuleType
):
super
().
__init__
(
kernel
)
self
.
_module
=
jit_module
self
.
_check_params
=
getattr
(
jit_module
,
"
check_params
"
)
self
.
_invoke
=
getattr
(
jit_module
,
"
invoke
"
)
def
__call__
(
self
,
**
kwargs
)
->
None
:
self
.
_check_params
(
**
kwargs
)
return
self
.
_invoke
(
**
kwargs
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment