Skip to content

Commit

Permalink
gh-218: add unary ops & vec map to package
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorOrachyov committed Aug 31, 2023
1 parent dfbfadf commit 2167b26
Show file tree
Hide file tree
Showing 12 changed files with 517 additions and 181 deletions.
50 changes: 47 additions & 3 deletions include/spla.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,44 @@ SPLA_API spla_Type spla_Type_FLOAT();

//////////////////////////////////////////////////////////////////////////////////////

/* Built-in unary element-wise operations */

SPLA_API spla_OpUnary spla_OpUnary_IDENTITY_INT();
SPLA_API spla_OpUnary spla_OpUnary_IDENTITY_UINT();
SPLA_API spla_OpUnary spla_OpUnary_IDENTITY_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_AINV_INT();
SPLA_API spla_OpUnary spla_OpUnary_AINV_UINT();
SPLA_API spla_OpUnary spla_OpUnary_AINV_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_MINV_INT();
SPLA_API spla_OpUnary spla_OpUnary_MINV_UINT();
SPLA_API spla_OpUnary spla_OpUnary_MINV_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_LNOT_INT();
SPLA_API spla_OpUnary spla_OpUnary_LNOT_UINT();
SPLA_API spla_OpUnary spla_OpUnary_LNOT_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_UONE_INT();
SPLA_API spla_OpUnary spla_OpUnary_UONE_UINT();
SPLA_API spla_OpUnary spla_OpUnary_UONE_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_ABS_INT();
SPLA_API spla_OpUnary spla_OpUnary_ABS_UINT();
SPLA_API spla_OpUnary spla_OpUnary_ABS_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_BNOT_INT();
SPLA_API spla_OpUnary spla_OpUnary_BNOT_UINT();
SPLA_API spla_OpUnary spla_OpUnary_SQRT_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_LOG_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_EXP_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_SIN_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_COS_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_TAN_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_ASIN_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_ACOS_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_ATAN_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_CEIL_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_FLOOR_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_ROUND_FLOAT();
SPLA_API spla_OpUnary spla_OpUnary_TRUNC_FLOAT();

//////////////////////////////////////////////////////////////////////////////////////

/* Built-in binary element-wise operations */

SPLA_API spla_OpBinary spla_OpBinary_PLUS_INT();
Expand All @@ -177,15 +215,21 @@ SPLA_API spla_OpBinary spla_OpBinary_FIRST_FLOAT();
SPLA_API spla_OpBinary spla_OpBinary_SECOND_INT();
SPLA_API spla_OpBinary spla_OpBinary_SECOND_UINT();
SPLA_API spla_OpBinary spla_OpBinary_SECOND_FLOAT();
SPLA_API spla_OpBinary spla_OpBinary_ONE_INT();
SPLA_API spla_OpBinary spla_OpBinary_ONE_UINT();
SPLA_API spla_OpBinary spla_OpBinary_ONE_FLOAT();
SPLA_API spla_OpBinary spla_OpBinary_BONE_INT();
SPLA_API spla_OpBinary spla_OpBinary_BONE_UINT();
SPLA_API spla_OpBinary spla_OpBinary_BONE_FLOAT();
SPLA_API spla_OpBinary spla_OpBinary_MIN_INT();
SPLA_API spla_OpBinary spla_OpBinary_MIN_UINT();
SPLA_API spla_OpBinary spla_OpBinary_MIN_FLOAT();
SPLA_API spla_OpBinary spla_OpBinary_MAX_INT();
SPLA_API spla_OpBinary spla_OpBinary_MAX_UINT();
SPLA_API spla_OpBinary spla_OpBinary_MAX_FLOAT();
SPLA_API spla_OpBinary spla_OpBinary_LOR_INT();
SPLA_API spla_OpBinary spla_OpBinary_LOR_UINT();
SPLA_API spla_OpBinary spla_OpBinary_LOR_FLOAT();
SPLA_API spla_OpBinary spla_OpBinary_LAND_INT();
SPLA_API spla_OpBinary spla_OpBinary_LAND_UINT();
SPLA_API spla_OpBinary spla_OpBinary_LAND_FLOAT();
SPLA_API spla_OpBinary spla_OpBinary_BOR_INT();
SPLA_API spla_OpBinary spla_OpBinary_BOR_UINT();
SPLA_API spla_OpBinary spla_OpBinary_BAND_INT();
Expand Down
55 changes: 52 additions & 3 deletions include/spla/op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,46 @@ namespace spla {
SPLA_API static ref_ptr<OpSelect> make_float(std::string name, std::string code, std::function<bool(T_FLOAT)> function);
};

//////////////////////////////// Unary ////////////////////////////////

SPLA_API extern ref_ptr<OpUnary> IDENTITY_INT;
SPLA_API extern ref_ptr<OpUnary> IDENTITY_UINT;
SPLA_API extern ref_ptr<OpUnary> IDENTITY_FLOAT;
SPLA_API extern ref_ptr<OpUnary> AINV_INT;
SPLA_API extern ref_ptr<OpUnary> AINV_UINT;
SPLA_API extern ref_ptr<OpUnary> AINV_FLOAT;
SPLA_API extern ref_ptr<OpUnary> MINV_INT;
SPLA_API extern ref_ptr<OpUnary> MINV_UINT;
SPLA_API extern ref_ptr<OpUnary> MINV_FLOAT;
SPLA_API extern ref_ptr<OpUnary> LNOT_INT;
SPLA_API extern ref_ptr<OpUnary> LNOT_UINT;
SPLA_API extern ref_ptr<OpUnary> LNOT_FLOAT;
SPLA_API extern ref_ptr<OpUnary> UONE_INT;
SPLA_API extern ref_ptr<OpUnary> UONE_UINT;
SPLA_API extern ref_ptr<OpUnary> UONE_FLOAT;
SPLA_API extern ref_ptr<OpUnary> ABS_INT;
SPLA_API extern ref_ptr<OpUnary> ABS_UINT;
SPLA_API extern ref_ptr<OpUnary> ABS_FLOAT;

SPLA_API extern ref_ptr<OpUnary> BNOT_INT;
SPLA_API extern ref_ptr<OpUnary> BNOT_UINT;

SPLA_API extern ref_ptr<OpUnary> SQRT_FLOAT;
SPLA_API extern ref_ptr<OpUnary> LOG_FLOAT;
SPLA_API extern ref_ptr<OpUnary> EXP_FLOAT;
SPLA_API extern ref_ptr<OpUnary> SIN_FLOAT;
SPLA_API extern ref_ptr<OpUnary> COS_FLOAT;
SPLA_API extern ref_ptr<OpUnary> TAN_FLOAT;
SPLA_API extern ref_ptr<OpUnary> ASIN_FLOAT;
SPLA_API extern ref_ptr<OpUnary> ACOS_FLOAT;
SPLA_API extern ref_ptr<OpUnary> ATAN_FLOAT;
SPLA_API extern ref_ptr<OpUnary> CEIL_FLOAT;
SPLA_API extern ref_ptr<OpUnary> FLOOR_FLOAT;
SPLA_API extern ref_ptr<OpUnary> ROUND_FLOAT;
SPLA_API extern ref_ptr<OpUnary> TRUNC_FLOAT;

//////////////////////////////// Binary ////////////////////////////////

SPLA_API extern ref_ptr<OpBinary> PLUS_INT;
SPLA_API extern ref_ptr<OpBinary> PLUS_UINT;
SPLA_API extern ref_ptr<OpBinary> PLUS_FLOAT;
Expand All @@ -117,9 +157,9 @@ namespace spla {
SPLA_API extern ref_ptr<OpBinary> SECOND_UINT;
SPLA_API extern ref_ptr<OpBinary> SECOND_FLOAT;

SPLA_API extern ref_ptr<OpBinary> ONE_INT;
SPLA_API extern ref_ptr<OpBinary> ONE_UINT;
SPLA_API extern ref_ptr<OpBinary> ONE_FLOAT;
SPLA_API extern ref_ptr<OpBinary> BONE_INT;
SPLA_API extern ref_ptr<OpBinary> BONE_UINT;
SPLA_API extern ref_ptr<OpBinary> BONE_FLOAT;

SPLA_API extern ref_ptr<OpBinary> MIN_INT;
SPLA_API extern ref_ptr<OpBinary> MIN_UINT;
Expand All @@ -128,13 +168,22 @@ namespace spla {
SPLA_API extern ref_ptr<OpBinary> MAX_UINT;
SPLA_API extern ref_ptr<OpBinary> MAX_FLOAT;

SPLA_API extern ref_ptr<OpBinary> LOR_INT;
SPLA_API extern ref_ptr<OpBinary> LOR_UINT;
SPLA_API extern ref_ptr<OpBinary> LOR_FLOAT;
SPLA_API extern ref_ptr<OpBinary> LAND_INT;
SPLA_API extern ref_ptr<OpBinary> LAND_UINT;
SPLA_API extern ref_ptr<OpBinary> LAND_FLOAT;

SPLA_API extern ref_ptr<OpBinary> BOR_INT;
SPLA_API extern ref_ptr<OpBinary> BOR_UINT;
SPLA_API extern ref_ptr<OpBinary> BAND_INT;
SPLA_API extern ref_ptr<OpBinary> BAND_UINT;
SPLA_API extern ref_ptr<OpBinary> BXOR_INT;
SPLA_API extern ref_ptr<OpBinary> BXOR_UINT;

//////////////////////////////// Select ////////////////////////////////

SPLA_API extern ref_ptr<OpSelect> EQZERO_INT;
SPLA_API extern ref_ptr<OpSelect> EQZERO_UINT;
SPLA_API extern ref_ptr<OpSelect> EQZERO_FLOAT;
Expand Down
3 changes: 3 additions & 0 deletions python/example.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from pyspla import *

v = Vector.from_lists([0, 1, 3], [5, -1, 3], 4, INT)
print(v.map(INT.AINV))
51 changes: 1 addition & 50 deletions python/pyspla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
| rgg_n_2_23_s0 | 8.4M | 127.0M | 15.1 | 3.9 | 40.0 | [link](https://suitesparse-collection-website.herokuapp.com/MM/DIMACS10/rgg_n_2_23_s0.tar.gz) |
| road_central | 14.1M | 33.9M | 2.4 | 0.9 | 8.0 | [link](http://sparse.tamu.edu/DIMACS10/road_central) |
Containers
----------
Expand All @@ -115,20 +114,6 @@
managed by container internally. All required format conversion done
in the context of particular primitive usage.
- `Matrix`. Generalized statically-typed sparse storage-invariant matrix primitive.
- `Vector`. Generalized statically-typed sparse storage-invariant vector primitive.
- `Scalar`. Generalized statically-typed scalar primitive.
Schedule
--------
Schedule allows to build sequence of tasks to be executed. It allows user
control the order of the tasks' execution, parallel execution of tasks
on some level, notification on some steps completion and etc.
- `Schedule`. Schedule object which may be executed by library.
- `Task`. A particular wort to be done inside a step of schedule.
Types
-----
Expand All @@ -138,11 +123,6 @@
can interpret stored data as her/she wants. Spla types set is limited due to the nature
of GPUs accelerations, where arbitrary layout of data causes significant performance penalties.
- `BOOL`. 4-byte-sized signed logical value (auxiliary type).
- `INT`. 4-byte-sized signed integral value.
- `UINT`. 4-byte-sized unsigned integral value.
- `FLOAT`. 4-byte-sized single-precision floating point value.
Ops
---
Expand All @@ -151,42 +131,13 @@
operations, binary operations used for reductions and products, select operations used for
filtration and mask application.
List of built-in binary operations:
| Name | Type | Meaning |
|:--------|:------------|:---------------|
|`PLUS` | binary(x,y) | r = x + y |
|`MINUS` | binary(x,y) | r = x - y |
|`MULT` | binary(x,y) | r = x * y |
|`DIV` | binary(x,y) | r = x / y |
|`FIRST` | binary(x,y) | r = x |
|`SECOND` | binary(x,y) | r = y |
|`ONE` | binary(x,y) | r = 1 |
|`MIN` | binary(x,y) | r = min(x, y) |
|`MAX` | binary(x,y) | r = max(x, y) |
|`BOR` | binary(x,y) | r = x or y |
|`BAND` | binary(x,y) | r = x & y |
|`BXOR` | binary(x,y) | r = x ^ y |
List of built-in select operations:
| Name | Type | Meaning |
|:--------|:------------|:---------------|
|`EQZERO` | select(x) | x == 0 |
|`NQZERO` | select(x) | x != 0 |
|`GTZERO` | select(x) | x > 0 |
|`GEZERO` | select(x) | x >= 0 |
|`LTZERO` | select(x) | x < 0 |
|`LEZERO` | select(x) | x <= 0 |
|`ALWAYS` | select(x) | true |
|`NEVER` | select(x) | false |
Details
-------
Spla C/C++ backend compiled library is automatically loaded and initialized on package import.
State of the library managed by internal `bridge` module. All resources are unloaded automatically
on package exit. Library state finalized automatically.
"""

__copyright__ = "Copyright (c) 2021-2023 SparseLinearAlgebra"
Expand Down
92 changes: 86 additions & 6 deletions python/pyspla/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,74 @@ def load_library(lib_path):
_spla.spla_Type_FLOAT.restype = _object_t
_spla.spla_Type_FLOAT.argtypes = []

_spla.spla_OpUnary_IDENTITY_INT.restype = _object_t
_spla.spla_OpUnary_IDENTITY_UINT.restype = _object_t
_spla.spla_OpUnary_IDENTITY_FLOAT.restype = _object_t
_spla.spla_OpUnary_AINV_INT.restype = _object_t
_spla.spla_OpUnary_AINV_UINT.restype = _object_t
_spla.spla_OpUnary_AINV_FLOAT.restype = _object_t
_spla.spla_OpUnary_MINV_INT.restype = _object_t
_spla.spla_OpUnary_MINV_UINT.restype = _object_t
_spla.spla_OpUnary_MINV_FLOAT.restype = _object_t
_spla.spla_OpUnary_LNOT_INT.restype = _object_t
_spla.spla_OpUnary_LNOT_UINT.restype = _object_t
_spla.spla_OpUnary_LNOT_FLOAT.restype = _object_t
_spla.spla_OpUnary_UONE_INT.restype = _object_t
_spla.spla_OpUnary_UONE_UINT.restype = _object_t
_spla.spla_OpUnary_UONE_FLOAT.restype = _object_t
_spla.spla_OpUnary_ABS_INT.restype = _object_t
_spla.spla_OpUnary_ABS_UINT.restype = _object_t
_spla.spla_OpUnary_ABS_FLOAT.restype = _object_t
_spla.spla_OpUnary_BNOT_INT.restype = _object_t
_spla.spla_OpUnary_BNOT_UINT.restype = _object_t
_spla.spla_OpUnary_SQRT_FLOAT.restype = _object_t
_spla.spla_OpUnary_LOG_FLOAT.restype = _object_t
_spla.spla_OpUnary_EXP_FLOAT.restype = _object_t
_spla.spla_OpUnary_SIN_FLOAT.restype = _object_t
_spla.spla_OpUnary_COS_FLOAT.restype = _object_t
_spla.spla_OpUnary_TAN_FLOAT.restype = _object_t
_spla.spla_OpUnary_ASIN_FLOAT.restype = _object_t
_spla.spla_OpUnary_ACOS_FLOAT.restype = _object_t
_spla.spla_OpUnary_ATAN_FLOAT.restype = _object_t
_spla.spla_OpUnary_CEIL_FLOAT.restype = _object_t
_spla.spla_OpUnary_FLOOR_FLOAT.restype = _object_t
_spla.spla_OpUnary_ROUND_FLOAT.restype = _object_t
_spla.spla_OpUnary_TRUNC_FLOAT.restype = _object_t

_spla.spla_OpUnary_IDENTITY_INT.argtypes = []
_spla.spla_OpUnary_IDENTITY_UINT.argtypes = []
_spla.spla_OpUnary_IDENTITY_FLOAT.argtypes = []
_spla.spla_OpUnary_AINV_INT.argtypes = []
_spla.spla_OpUnary_AINV_UINT.argtypes = []
_spla.spla_OpUnary_AINV_FLOAT.argtypes = []
_spla.spla_OpUnary_MINV_INT.argtypes = []
_spla.spla_OpUnary_MINV_UINT.argtypes = []
_spla.spla_OpUnary_MINV_FLOAT.argtypes = []
_spla.spla_OpUnary_LNOT_INT.argtypes = []
_spla.spla_OpUnary_LNOT_UINT.argtypes = []
_spla.spla_OpUnary_LNOT_FLOAT.argtypes = []
_spla.spla_OpUnary_UONE_INT.argtypes = []
_spla.spla_OpUnary_UONE_UINT.argtypes = []
_spla.spla_OpUnary_UONE_FLOAT.argtypes = []
_spla.spla_OpUnary_ABS_INT.argtypes = []
_spla.spla_OpUnary_ABS_UINT.argtypes = []
_spla.spla_OpUnary_ABS_FLOAT.argtypes = []
_spla.spla_OpUnary_BNOT_INT.argtypes = []
_spla.spla_OpUnary_BNOT_UINT.argtypes = []
_spla.spla_OpUnary_SQRT_FLOAT.argtypes = []
_spla.spla_OpUnary_LOG_FLOAT.argtypes = []
_spla.spla_OpUnary_EXP_FLOAT.argtypes = []
_spla.spla_OpUnary_SIN_FLOAT.argtypes = []
_spla.spla_OpUnary_COS_FLOAT.argtypes = []
_spla.spla_OpUnary_TAN_FLOAT.argtypes = []
_spla.spla_OpUnary_ASIN_FLOAT.argtypes = []
_spla.spla_OpUnary_ACOS_FLOAT.argtypes = []
_spla.spla_OpUnary_ATAN_FLOAT.argtypes = []
_spla.spla_OpUnary_CEIL_FLOAT.argtypes = []
_spla.spla_OpUnary_FLOOR_FLOAT.argtypes = []
_spla.spla_OpUnary_ROUND_FLOAT.argtypes = []
_spla.spla_OpUnary_TRUNC_FLOAT.argtypes = []

_spla.spla_OpBinary_PLUS_INT.restype = _object_t
_spla.spla_OpBinary_PLUS_UINT.restype = _object_t
_spla.spla_OpBinary_PLUS_FLOAT.restype = _object_t
Expand All @@ -216,15 +284,21 @@ def load_library(lib_path):
_spla.spla_OpBinary_SECOND_INT.restype = _object_t
_spla.spla_OpBinary_SECOND_UINT.restype = _object_t
_spla.spla_OpBinary_SECOND_FLOAT.restype = _object_t
_spla.spla_OpBinary_ONE_INT.restype = _object_t
_spla.spla_OpBinary_ONE_UINT.restype = _object_t
_spla.spla_OpBinary_ONE_FLOAT.restype = _object_t
_spla.spla_OpBinary_BONE_INT.restype = _object_t
_spla.spla_OpBinary_BONE_UINT.restype = _object_t
_spla.spla_OpBinary_BONE_FLOAT.restype = _object_t
_spla.spla_OpBinary_MIN_INT.restype = _object_t
_spla.spla_OpBinary_MIN_UINT.restype = _object_t
_spla.spla_OpBinary_MIN_FLOAT.restype = _object_t
_spla.spla_OpBinary_MAX_INT.restype = _object_t
_spla.spla_OpBinary_MAX_UINT.restype = _object_t
_spla.spla_OpBinary_MAX_FLOAT.restype = _object_t
_spla.spla_OpBinary_LOR_INT.restype = _object_t
_spla.spla_OpBinary_LOR_UINT.restype = _object_t
_spla.spla_OpBinary_LOR_FLOAT.restype = _object_t
_spla.spla_OpBinary_LAND_INT.restype = _object_t
_spla.spla_OpBinary_LAND_UINT.restype = _object_t
_spla.spla_OpBinary_LAND_FLOAT.restype = _object_t
_spla.spla_OpBinary_BOR_INT.restype = _object_t
_spla.spla_OpBinary_BOR_UINT.restype = _object_t
_spla.spla_OpBinary_BAND_INT.restype = _object_t
Expand Down Expand Up @@ -253,15 +327,21 @@ def load_library(lib_path):
_spla.spla_OpBinary_SECOND_INT.argtypes = []
_spla.spla_OpBinary_SECOND_UINT.argtypes = []
_spla.spla_OpBinary_SECOND_FLOAT.argtypes = []
_spla.spla_OpBinary_ONE_INT.argtypes = []
_spla.spla_OpBinary_ONE_UINT.argtypes = []
_spla.spla_OpBinary_ONE_FLOAT.argtypes = []
_spla.spla_OpBinary_BONE_INT.argtypes = []
_spla.spla_OpBinary_BONE_UINT.argtypes = []
_spla.spla_OpBinary_BONE_FLOAT.argtypes = []
_spla.spla_OpBinary_MIN_INT.argtypes = []
_spla.spla_OpBinary_MIN_UINT.argtypes = []
_spla.spla_OpBinary_MIN_FLOAT.argtypes = []
_spla.spla_OpBinary_MAX_INT.argtypes = []
_spla.spla_OpBinary_MAX_UINT.argtypes = []
_spla.spla_OpBinary_MAX_FLOAT.argtypes = []
_spla.spla_OpBinary_LOR_INT.argtypes = []
_spla.spla_OpBinary_LOR_UINT.argtypes = []
_spla.spla_OpBinary_LOR_FLOAT.argtypes = []
_spla.spla_OpBinary_LAND_INT.argtypes = []
_spla.spla_OpBinary_LAND_UINT.argtypes = []
_spla.spla_OpBinary_LAND_FLOAT.argtypes = []
_spla.spla_OpBinary_BOR_INT.argtypes = []
_spla.spla_OpBinary_BOR_UINT.argtypes = []
_spla.spla_OpBinary_BAND_INT.argtypes = []
Expand Down
Loading

0 comments on commit 2167b26

Please sign in to comment.