-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from sklam/libgdf
Delegate basic arithmetic and logical binops to libgdf.
- Loading branch information
Showing
6 changed files
with
308 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,15 @@ | ||
name: pycudf_testing_py35 | ||
channels: | ||
- numba | ||
- gpuopenanalytics/label/dev | ||
- defaults | ||
dependencies: | ||
- accelerate_cudalib=2.0=0 | ||
- cudatoolkit=8.0=0 | ||
- mkl=2017.0.1=0 | ||
- numpy=1.12.1=py35_0 | ||
- openssl=1.0.2k=1 | ||
- pip=9.0.1=py35_1 | ||
- py=1.4.33=py35_0 | ||
- pytest=3.0.7=py35_0 | ||
- python=3.5.3=1 | ||
- readline=6.2=2 | ||
- setuptools=27.2.0=py35_0 | ||
- sqlite=3.13.0=0 | ||
- tk=8.5.18=0 | ||
- wheel=0.29.0=py35_0 | ||
- xz=5.2.2=1 | ||
- zlib=1.2.8=3 | ||
- llvmlite=0.18 | ||
- numba=0.33 | ||
- pip: | ||
- flatbuffers==2015.12.22.1 | ||
- pytest=3.0.7 | ||
- python=3.5.3 | ||
- setuptools=27.2.0 | ||
- accelerate_cudalib=2.0 | ||
- cudatoolkit=8.0 | ||
- llvmlite>=0.18 | ||
- numpy=1.12.1 | ||
- numba>=0.33 | ||
- libgdf_cffi>=0.1.0a1.dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
This file provide binding to the libgdf library. | ||
""" | ||
import numpy as np | ||
|
||
from libgdf_cffi import ffi, libgdf | ||
|
||
|
||
def columnview(size, data, mask=None, dtype=None): | ||
""" | ||
Make a column view. | ||
""" | ||
def unwrap(buffer): | ||
if buffer is None: | ||
return ffi.NULL | ||
devary = buffer.to_gpu_array() | ||
return ffi.cast('void*', devary.device_ctypes_pointer.value) | ||
|
||
dtype = dtype or data.dtype | ||
colview = ffi.new('gdf_column*') | ||
libgdf.gdf_column_view(colview, unwrap(data), unwrap(mask), size, | ||
np_to_gdf_dtype(dtype)) | ||
|
||
return colview | ||
|
||
|
||
def apply_binaryop(binop, lhs, rhs, out): | ||
"""Apply binary operator *binop* to operands *lhs* and *rhs*. | ||
The result is stored to *out*. | ||
""" | ||
binop(lhs._cffi_view, rhs._cffi_view, out._cffi_view) | ||
|
||
|
||
def apply_unaryop(unaop, inp, out): | ||
"""Apply unary operator *unaop* to *inp* and store to *out*. | ||
""" | ||
unaop(inp._cffi_view, out._cffi_view) | ||
|
||
|
||
def np_to_gdf_dtype(dtype): | ||
"""Util to convert numpy dtype to gdf dtype. | ||
""" | ||
return { | ||
np.float64: libgdf.GDF_FLOAT64, | ||
np.float32: libgdf.GDF_FLOAT32, | ||
np.int64: libgdf.GDF_INT64, | ||
np.int32: libgdf.GDF_INT32, | ||
np.int8: libgdf.GDF_INT8, | ||
np.bool_: libgdf.GDF_INT8, | ||
}[np.dtype(dtype).type] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.