Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pystencils_autodiff
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
pycodegen
pystencils_autodiff
Commits
48d20529
Commit
48d20529
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Optionally generate PyTorchModule without Python bindings
parent
977960a4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencils_autodiff/backends/astnodes.py
+2
-1
2 additions, 1 deletion
src/pystencils_autodiff/backends/astnodes.py
tests/backends/test_torch_native_compilation.py
+10
-8
10 additions, 8 deletions
tests/backends/test_torch_native_compilation.py
with
12 additions
and
9 deletions
src/pystencils_autodiff/backends/astnodes.py
+
2
−
1
View file @
48d20529
...
...
@@ -74,7 +74,7 @@ class TorchModule(JinjaCppFile):
def
backend
(
self
):
return
'
gpucuda
'
if
self
.
is_cuda
else
'
c
'
def
__init__
(
self
,
module_name
,
kernel_asts
):
def
__init__
(
self
,
module_name
,
kernel_asts
,
with_python_bindings
=
True
):
"""
Create a C++ module with forward and optional backward_kernels
:param forward_kernel_ast: one or more kernel ASTs (can have any C dialect)
...
...
@@ -95,6 +95,7 @@ class TorchModule(JinjaCppFile):
'
python_bindings
'
:
self
.
PYTHON_BINDINGS_CLASS
(
module_name
,
[
self
.
PYTHON_FUNCTION_WRAPPING_CLASS
(
a
)
for
a
in
wrapper_functions
])
if
with_python_bindings
else
''
}
super
().
__init__
(
ast_dict
)
...
...
This diff is collapsed.
Click to expand it.
tests/backends/test_torch_native_compilation.py
+
10
−
8
View file @
48d20529
...
...
@@ -9,15 +9,15 @@ from os.path import dirname, isfile, join
import
numpy
as
np
import
pytest
import
sympy
import
pystencils
import
sympy
from
pystencils_autodiff
import
create_backward_assignments
from
pystencils_autodiff._file_io
import
write_cached_content
from
pystencils_autodiff.backends.astnodes
import
PybindModule
,
TorchModule
torch
=
pytest
.
importorskip
(
'
torch
'
)
pytestmark
=
pytest
.
mark
.
skipif
(
subprocess
.
call
([
'
ninja
'
,
'
--v
'
])
!=
0
,
pytestmark
=
pytest
.
mark
.
skipif
(
subprocess
.
call
([
'
ninja
'
,
'
--v
ersion
'
])
!=
0
,
reason
=
'
torch compilation requires ninja
'
)
...
...
@@ -78,7 +78,8 @@ def test_torch_native_compilation_cpu():
assert
'
call_backward
'
in
dir
(
torch_extension
)
def
test_pybind11_compilation_cpu
():
@pytest.mark.parametrize
(
'
with_python_bindings
'
,
(
'
with_python_bindings
'
,
False
))
def
test_pybind11_compilation_cpu
(
with_python_bindings
):
pytest
.
importorskip
(
'
pybind11
'
)
pytest
.
importorskip
(
'
cppimport
'
)
...
...
@@ -100,13 +101,14 @@ def test_pybind11_compilation_cpu():
forward_ast
.
function_name
=
'
forward
'
backward_ast
=
pystencils
.
create_kernel
(
backward_assignments
,
target
)
backward_ast
.
function_name
=
'
backward
'
module
=
PybindModule
(
module_name
,
[
forward_ast
,
backward_ast
])
module
=
PybindModule
(
module_name
,
[
forward_ast
,
backward_ast
]
,
with_python_bindings
=
with_python_bindings
)
print
(
module
)
pybind_extension
=
module
.
compile
()
assert
pybind_extension
is
not
None
assert
'
call_forward
'
in
dir
(
pybind_extension
)
assert
'
call_backward
'
in
dir
(
pybind_extension
)
if
with_python_bindings
:
pybind_extension
=
module
.
compile
()
assert
pybind_extension
is
not
None
assert
'
call_forward
'
in
dir
(
pybind_extension
)
assert
'
call_backward
'
in
dir
(
pybind_extension
)
@pytest.mark.skipif
(
"
TRAVIS
"
in
os
.
environ
,
reason
=
"
nvcc compilation currently not working on TRAVIS
"
)
...
...
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