Skip to content

Commit

Permalink
Enhance Python API to support retrieval of all available ISAs (#51)
Browse files Browse the repository at this point in the history
* Enhance Python API to support retrieval of all available ISAs

* add rua! ci

* migrate to ruapu_rua()
  • Loading branch information
Yoh-Z authored Feb 29, 2024
1 parent fdead14 commit 070f52d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
cd python
pip3 install .
python3 -c 'import ruapu; print(ruapu.supports("neon")); print(ruapu.supports(isa="avx"))'
python3 -c 'import ruapu; print(ruapu.rua())'
- name: build-test-rust
run: |
rustup update stable
Expand All @@ -61,6 +62,7 @@ jobs:
cd python
pip3 install .
python3 -c 'import ruapu; print(ruapu.supports("neon")); print(ruapu.supports(isa="avx"))'
python3 -c 'import ruapu; print(ruapu.rua())'
- name: build-test-rust
run: |
rustup update stable
Expand All @@ -84,6 +86,7 @@ jobs:
cd python
pip3 install .
python3 -c 'import ruapu; print(ruapu.supports("neon")); print(ruapu.supports(isa="avx"))'
python3 -c 'import ruapu; print(ruapu.rua())'
- name: build-test-rust
run: |
rustup update stable
Expand Down Expand Up @@ -113,6 +116,7 @@ jobs:
cd python
pip3 install .
python3 -c 'import ruapu; print(ruapu.supports("neon")); print(ruapu.supports(isa="avx"))'
python3 -c 'import ruapu; print(ruapu.rua())'
- name: build-test-rust
run: |
rustup update stable
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ ruapu.supports("avx2")

ruapu.supports(isa="avx2")
# True

ruapu.rua()
#(mmx', 'sse', 'sse2', 'sse3', 'ssse3', 'sse41', 'sse42', 'avx', 'f16c', 'fma', 'avx2')
```
</td></tr>
</table>
Expand Down
24 changes: 24 additions & 0 deletions python/ruapu-binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,33 @@ static PyObject *ruapu_supports_py(PyObject *self, PyObject *args, PyObject *kwa
Py_RETURN_FALSE;
}

static PyObject *get_isa_items_py(PyObject *self, PyObject *args, PyObject *kwargs)
{
const char* const* isa_supported = ruapu_rua();
int total = 0;
while(*isa_supported)
{
total++;
isa_supported++;
}

isa_supported = ruapu_rua();
PyObject* supported_isa_py = PyTuple_New(total);

int tuple_idx = 0;
while(*isa_supported)
{
PyTuple_SetItem(supported_isa_py, tuple_idx++, PyUnicode_FromString(*isa_supported));
isa_supported++;
}

return supported_isa_py;
}

static PyMethodDef ruapu_methods[] =
{
{"supports", ruapu_supports_py, METH_VARARGS | METH_KEYWORDS, "Check if the CPU supports an instruction set"},
{"rua", get_isa_items_py, METH_VARARGS | METH_KEYWORDS, "Get the instruction sets supported by the current CPU"},
{NULL, NULL, 0, NULL}
};

Expand Down

0 comments on commit 070f52d

Please sign in to comment.