cython - cupy 支持 cython(例如缓冲索引)吗?

标签 cython chainer cupy

我已经实现了自己定义的chainer Link,但是因为它太慢了。 我已经实现了我的代码的 cython CPU 版本。但我想通过 GPU 进一步提高速度。所以我测试了以下代码,但失败了:

%%cython

import numpy as np
cimport numpy as np
import cupy as cp
cimport cupy as cp
cdef class A:
    def __init__(self):
        pass

    cdef cp_test(self, cp.ndarray[cp.float_t, ndim=2] arr):
        return cp.sum(arr)

a = A()
arr = cp.arange(100).reshape(20,50)
print(a.cp_test(arr))

报告:

    cdef cp_test(self, cp.ndarray[cp.float_t, ndim=2] arr):
                      ^
------------------------------------------------------------

C:\Users\.ipython\cython\_cython_magic_d4940a274af88f0257c368b8a5d0e3f5.pyx:13:23: 'ndarray' is not a type identifier

最佳答案

抱歉,CuPy 目前不提供 cython 接口(interface)(我是 CuPy 开发人员之一)。
功能请求开放于https://github.com/cupy/cupy/issues/130 .

关于cython - cupy 支持 cython(例如缓冲索引)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46510663/

相关文章:

python - 如何在 Chainer 中对变量应用优化器?

python - 如何在 Chainer 中测量每层的时间

python - @cupy.fuse cupy python 装饰器在哪里记录?

gpu - NetworkX all_pairs_dijkstras 的 CuGraph 实现

cuda - anaconda如何pick cudatoolkit

python - 使用 Cython 包装返回 MPI 通信器的 C++ 函数

python - 我可以在 python 中使用什么方法代替 __file__ ?

python - Cython:C 级 int 与 PyLongObjects

python - 改进一个简单的 spring 网络的 numpy 实现

python - 预期类型错误 : numpy. ndarray 或 cuda.ndarray