Emanuel Rietveld
2018-02-26 13:53:03 UTC
Hi,
I'm trying to use PyCUDA with PyPy. With these two patches it seems to work...
(Taken from https://svn.boost.org/trac10/ticket/4125)
diff --git a/bpl_subset/libs/python/src/wrapper.cpp
b/bpl_subset/libs/python/src/wrapper.cpp
index f8feaef..8b1b884 100644
--- a/bpl_subset/libs/python/src/wrapper.cpp
+++ b/bpl_subset/libs/python/src/wrapper.cpp
@@ -25,7 +25,7 @@ namespace detail
if (
PyMethod_Check(m.get())
- && ((PyMethodObject*)m.get())->im_self == this->m_self
+ && PyMethod_GET_SELF(m.get()) == this->m_self
&& class_object->tp_dict != 0
)
{
@@ -34,7 +34,7 @@ namespace detail
}
- if (borrowed_f != ((PyMethodObject*)m.get())->im_func)
+ if (borrowed_f != PyMethod_GET_FUNCTION(m.get()))
return override(m);
}
}
(Taken from https://docs.python.org/3/library/platform.html)
diff --git a/pycuda/characterize.py b/pycuda/characterize.py
index 1c54af7..c66c448 100644
--- a/pycuda/characterize.py
+++ b/pycuda/characterize.py
@@ -1,13 +1,14 @@
from __future__ import division
from __future__ import absolute_import
+import sys
from pycuda.tools import context_dependent_memoize
import numpy as np
def platform_bits():
- return tuple.__itemsize__ * 8
-
+ if sys.maxsize > 2**32: return 64
+ else: return 32
Is there anything else I'd need to be mindful of? On this PyPy page
https://bitbucket.org/pypy/compatibility/wiki/Home PyCUDA is
explicitly listed as incompatible... However with the following patch
to the tests, I can run those too and they all pass.
diff --git a/test/test_cumath.py b/test/test_cumath.py
index 874ccb6..272ab5a 100644
--- a/test/test_cumath.py
+++ b/test/test_cumath.py
@@ -242,5 +242,5 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
exec (sys.argv[1])
else:
- from py.test.cmdline import main
+ from pytest import main
main([__file__])
diff --git a/test/test_driver.py b/test/test_driver.py
index f88a1d6..038cf64 100644
--- a/test/test_driver.py
+++ b/test/test_driver.py
@@ -961,5 +961,5 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
exec (sys.argv[1])
else:
- from py.test.cmdline import main
+ from pytest import main
main([__file__])
diff --git a/test/test_gpuarray.py b/test/test_gpuarray.py
index 93cc954..e38e2fd 100644
--- a/test/test_gpuarray.py
+++ b/test/test_gpuarray.py
@@ -1153,5 +1153,5 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
exec (sys.argv[1])
else:
- from py.test.cmdline import main
+ from pytest import main
main([__file__])
Thanks,
Emanuel
I'm trying to use PyCUDA with PyPy. With these two patches it seems to work...
(Taken from https://svn.boost.org/trac10/ticket/4125)
diff --git a/bpl_subset/libs/python/src/wrapper.cpp
b/bpl_subset/libs/python/src/wrapper.cpp
index f8feaef..8b1b884 100644
--- a/bpl_subset/libs/python/src/wrapper.cpp
+++ b/bpl_subset/libs/python/src/wrapper.cpp
@@ -25,7 +25,7 @@ namespace detail
if (
PyMethod_Check(m.get())
- && ((PyMethodObject*)m.get())->im_self == this->m_self
+ && PyMethod_GET_SELF(m.get()) == this->m_self
&& class_object->tp_dict != 0
)
{
@@ -34,7 +34,7 @@ namespace detail
}
- if (borrowed_f != ((PyMethodObject*)m.get())->im_func)
+ if (borrowed_f != PyMethod_GET_FUNCTION(m.get()))
return override(m);
}
}
(Taken from https://docs.python.org/3/library/platform.html)
diff --git a/pycuda/characterize.py b/pycuda/characterize.py
index 1c54af7..c66c448 100644
--- a/pycuda/characterize.py
+++ b/pycuda/characterize.py
@@ -1,13 +1,14 @@
from __future__ import division
from __future__ import absolute_import
+import sys
from pycuda.tools import context_dependent_memoize
import numpy as np
def platform_bits():
- return tuple.__itemsize__ * 8
-
+ if sys.maxsize > 2**32: return 64
+ else: return 32
Is there anything else I'd need to be mindful of? On this PyPy page
https://bitbucket.org/pypy/compatibility/wiki/Home PyCUDA is
explicitly listed as incompatible... However with the following patch
to the tests, I can run those too and they all pass.
diff --git a/test/test_cumath.py b/test/test_cumath.py
index 874ccb6..272ab5a 100644
--- a/test/test_cumath.py
+++ b/test/test_cumath.py
@@ -242,5 +242,5 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
exec (sys.argv[1])
else:
- from py.test.cmdline import main
+ from pytest import main
main([__file__])
diff --git a/test/test_driver.py b/test/test_driver.py
index f88a1d6..038cf64 100644
--- a/test/test_driver.py
+++ b/test/test_driver.py
@@ -961,5 +961,5 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
exec (sys.argv[1])
else:
- from py.test.cmdline import main
+ from pytest import main
main([__file__])
diff --git a/test/test_gpuarray.py b/test/test_gpuarray.py
index 93cc954..e38e2fd 100644
--- a/test/test_gpuarray.py
+++ b/test/test_gpuarray.py
@@ -1153,5 +1153,5 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
exec (sys.argv[1])
else:
- from py.test.cmdline import main
+ from pytest import main
main([__file__])
Thanks,
Emanuel