Enhance Python API to support retrieval of all available ISAs (#51)

* Enhance Python API to support retrieval of all available ISAs

* add rua! ci

* migrate to ruapu_rua()
This commit is contained in:
Yoh 2024-02-29 21:36:35 +08:00 committed by GitHub
parent fdead14410
commit 070f52dda3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 0 deletions

View File

@ -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
@ -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
@ -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
@ -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

View File

@ -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>

View File

@ -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}
};