Skip to content

Commit

Permalink
Merge pull request inducer#4 from nouiz/reorg
Browse files Browse the repository at this point in the history
Numpy-like C-API interface for easier conversion in a separate header.
  • Loading branch information
abergeron committed Nov 13, 2013
2 parents ab5aba2 + 7428184 commit 3ba7fa6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pygpu/elemwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ def __init__(self, context, arguments, operation, preamble="",
self.preamble = preamble

self.contig_src = contiguous_kernel.render(preamble=self.preamble,
name="elemk",
name="elem_contig",
arguments=self.arguments,
expression=self.operation)
self.contig_k = gpuarray.GpuKernel(self.contig_src, "elemk",
self.contig_k = gpuarray.GpuKernel(self.contig_src, "elem_contig",
context=self.context,
cluda=True, **self.flags)
self._speckey = None
Expand Down Expand Up @@ -308,15 +308,16 @@ def prepare_args_contig(self, args, n, offsets):
kernel_args.insert(0, numpy.asarray(n, dtype='uint32'))
return kernel_args

def render_basic(self, nd):
return basic_kernel.render(preamble=self.preamble, name="elemk",
def render_basic(self, nd, name="elemk"):
return basic_kernel.render(preamble=self.preamble, name=name,
nd=nd, arguments=self.arguments,
expression=self.expression)

@lfu_cache()
def _make_basic(self, nd):
src = self.render_basic(nd)
return gpuarray.GpuKernel(src, "elemk", context=self.context,
name = "elem_" + str(nd)
src = self.render_basic(nd, name=name)
return gpuarray.GpuKernel(src, name, context=self.context,
cluda=True, **self.flags)

def prepare_args_basic(self, args, n, dims, strs, offsets):
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ SET(headers
compyte/kernel.h
compyte/types.h
compyte/util.h
compyte/pygpua_cuda.h
)

INSTALL(FILES ${headers} DESTINATION include/compyte)
Expand Down
35 changes: 35 additions & 0 deletions src/compyte/numpy_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file isn't recommanded. Using it make your code not able to work on OpenCL.
*
* But it allow faster conversion to this new library of existing code
*/
#include "extension.h"
#ifndef COMPYTE_BUFFER_CUDA_H
#define COMPYTE_BUFFER_CUDA_H

int PyGpuArray_NDIM(PyGpuArrayObject *arr) {
return arr->ga.nd;
}
size_t *PyGpuArray_DIMS(PyGpuArrayObject *arr) {
return arr->ga.dimensions;
}

ssize_t *PyGpuArray_STRIDES(PyGpuArrayObject* arr) {
return arr->ga.strides;
}
size_t PyGpuArray_DIM(PyGpuArrayObject* arr, int n) {
return arr->ga.dimensions[n];
}
ssize_t PyGpuArray_STRIDE(PyGpuArrayObject* arr, int n) {
return arr->ga.strides[n];
}
//int PyGpuArray_ITEMSIZE(PyGpuArrayObject* arr)
size_t PyGpuArray_SIZE(PyGpuArrayObject* arr) {
size_t size = 1;
for(int i=0; i< arr->ga.nd; i++) {
size *= arr->ga.dimensions[i];
}
return size;
}

#endif

0 comments on commit 3ba7fa6

Please sign in to comment.