-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Pearu Peterson <[email protected]>
- Loading branch information
1 parent
db80b6c
commit f816e23
Showing
28 changed files
with
4,127 additions
and
159 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
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
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
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 |
---|---|---|
|
@@ -22,4 +22,5 @@ and llvmlite tools. | |
api | ||
releases | ||
developer | ||
nrt | ||
envvars |
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,169 @@ | ||
|
||
Numba Runtime | ||
============= | ||
|
||
RBC includes a simplified implementation of the Numba Runtime written in pure | ||
LLVM, which differs from the original C-written implementation. This approach | ||
enables RBC to extend its support to a broader range of Python datatypes, | ||
including lists, sets, and strings, which was not possible with the previous | ||
implementation. Python ``dict`` is not supported as its implementation is | ||
written in C. | ||
|
||
|
||
List of NRT functions implemented | ||
--------------------------------- | ||
|
||
The RBC project includes some functions from the NRT module, with changes made | ||
as necessary to fit our specific use case. Here is a list of the functions we | ||
have implemented, along with any relevant comments. | ||
|
||
* ✔️ ``NRT_MemInfo_init`` | ||
* ✔️ ``NRT_MemInfo_alloc`` | ||
* ✔️ ``NRT_MemInfo_alloc_safe`` | ||
* ✔️ ``NRT_MemInfo_alloc_dtor`` | ||
* ✔️ ``NRT_MemInfo_alloc_dtor_safe`` | ||
* ✔️ ``NRT_Allocate`` | ||
* ✔️ ``NRT_Allocate_External`` | ||
* ✔️ ``NRT_MemInfo_call_dtor`` | ||
* ✔️ ``NRT_incref`` - Memory is managed by HeavyDB server. Thus, this function has an empty body | ||
* ✔️ ``NRT_decref`` - Similarly, this function also has an empty body | ||
* ✔️ ``NRT_MemInfo_data_fast`` | ||
* ✔️ ``NRT_MemInfo_new`` | ||
* ✔️ ``NRT_MemInfo_new_varsize_dtor`` | ||
* ✔️ ``NRT_MemInfo_varsize_alloc`` | ||
* ✔️ ``NRT_MemInfo_varsize_realloc`` | ||
* ✔️ ``NRT_MemInfo_varsize_free`` | ||
* ✔️ ``NRT_MemInfo_new_varsize`` | ||
* ✔️ ``NRT_MemInfo_alloc_safe_aligned`` - Calls the unaligned version for now | ||
* ✔️ ``NRT_Reallocate`` - ``realloc`` is implemented using ``allocate_varlen_buffer`` as the former may free previous allocated memory, which result in a double-free once the UD[T]F finishes execution | ||
* ✔️ ``NRT_dealloc`` | ||
* ✔️ ``NRT_Free`` - Memory is freed upon UD[T]F return. Thus, this function does not free any memory | ||
* ✔️ ``NRT_MemInfo_destroy`` | ||
|
||
|
||
How to debug NRT methods | ||
------------------------ | ||
|
||
By defining the environment variable ``RBC_DEBUG_NRT``, RBC will enable debug | ||
statements to each function call made to NRT. | ||
|
||
|
||
How to generate ``unicodetype_db.ll`` | ||
------------------------------------- | ||
|
||
Alongside with NRT, unicode strings also required functions which are | ||
implemented using C, in Numba. In RBC, those functions were copied to | ||
``unicodetype_db.h``. To generate the ``.ll`` file, run the clang command below | ||
to generate the bitcode file: | ||
|
||
.. code-block:: bash | ||
$ clang -S -emit-llvm -O2 -Ipath/to/numba unicodetype_db.h -o unicodetype_db.ll | ||
Supported Python Containers | ||
=========================== | ||
|
||
List | ||
---- | ||
|
||
* ✔️ ``list.append`` | ||
* ✔️ ``list.extend`` | ||
* ✔️ ``list.insert`` | ||
* ✔️ ``list.remove`` | ||
* ✔️ ``list.pop`` | ||
* ✔️ ``list.clear`` | ||
* ✔️ ``list.index`` | ||
* ✔️ ``list.count`` | ||
* ✔️ ``list.sort`` | ||
* ✔️ ``list.reverse`` | ||
* ✔️ ``list.copy`` | ||
|
||
Additionally, one can convert an array to a list with ``Array.to_list`` method. | ||
|
||
|
||
Set | ||
--- | ||
|
||
* ✔️ ``set.add`` | ||
* ✔️ ``set.clear`` | ||
* ✔️ ``set.copy`` | ||
* ✔️ ``set.difference`` | ||
* ✔️ ``set.difference_update`` | ||
* ✔️ ``set.discard`` | ||
* ✔️ ``set.intersection`` | ||
* ✔️ ``set.intersection_update`` | ||
* ✔️ ``set.isdisjoint`` | ||
* ✔️ ``set.issubset`` | ||
* ✔️ ``set.issuperset`` | ||
* ✔️ ``set.pop`` | ||
* ✔️ ``set.remove`` | ||
* ✔️ ``set.symmetric_difference`` | ||
* ✔️ ``set.symmetric_difference_update`` | ||
* ❌ ``set.union`` | ||
* ✔️ ``set.update`` | ||
|
||
|
||
String | ||
------ | ||
|
||
* ✔️ ``string.capitalize`` | ||
* ✔️ ``string.casefold`` | ||
* ✔️ ``string.center`` | ||
* ✔️ ``string.count`` | ||
* ❌ ``string.encode`` | ||
* ✔️ ``string.endswith`` | ||
* ✔️ ``string.expandtabs`` | ||
* ✔️ ``string.find`` | ||
* ❌ ``string.format`` | ||
* ❌ ``string.format_map`` | ||
* ✔️ ``string.index`` | ||
* ✔️ ``string.isalnum`` | ||
* ✔️ ``string.isalpha`` | ||
* ✔️ ``string.isascii`` | ||
* ✔️ ``string.isdecimal`` | ||
* ✔️ ``string.isdigit`` | ||
* ✔️ ``string.isidentifier`` | ||
* ✔️ ``string.islower`` | ||
* ✔️ ``string.isnumeric`` | ||
* ✔️ ``string.isprintable`` | ||
* ✔️ ``string.isspace`` | ||
* ✔️ ``string.istitle`` | ||
* ✔️ ``string.isupper`` | ||
* ✔️ ``string.join`` | ||
* ✔️ ``string.ljust`` | ||
* ✔️ ``string.lower`` | ||
* ✔️ ``string.lstrip`` | ||
* ❌ ``string.maketrans`` | ||
* ❌ ``string.partition`` | ||
* ✔️ ``string.removeprefix`` | ||
* ✔️ ``string.removesuffix`` | ||
* ✔️ ``string.replace`` | ||
* ✔️ ``string.rfind`` | ||
* ✔️ ``string.rindex`` | ||
* ✔️ ``string.rjust`` | ||
* ❌ ``string.rpartition`` | ||
* ✔️ ``string.rsplit`` | ||
* ✔️ ``string.rstrip`` | ||
* ✔️ ``string.split`` | ||
* ✔️ ``string.splitlines`` | ||
* ✔️ ``string.startswith`` | ||
* ✔️ ``string.strip`` | ||
* ✔️ ``string.swapcase`` | ||
* ✔️ ``string.title`` | ||
* ❌ ``string.translate`` | ||
* ✔️ ``string.upper`` | ||
* ✔️ ``string.zfill`` | ||
|
||
Additionally, one can convert a text encoding none type to a python string using | ||
``TextEncodingNone.to_string`` method. | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
Tests are a good reference for using the methods defined above: | ||
|
||
* `List <https://github.com/xnd-project/rbc/blob/main/rbc/tests/heavydb/test_nrt_list.py>`_ | ||
* `Set <https://github.com/xnd-project/rbc/blob/main/rbc/tests/heavydb/test_nrt_set.py>`_ | ||
* `String <https://github.com/xnd-project/rbc/blob/main/rbc/tests/heavydb/test_nrt_string.py>`_ |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -331,6 +331,7 @@ | |
} | ||
], | ||
"source": [ | ||
"# NBVAL_IGNORE_OUTPUT\n", | ||
"rjit.stop_server()" | ||
] | ||
} | ||
|
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
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,18 @@ | ||
__all__ = ['allocate_varlen_buffer'] | ||
|
||
from numba.core import cgutils | ||
from llvmlite import ir | ||
|
||
|
||
def allocate_varlen_buffer(builder, element_count, element_size): | ||
""" | ||
Allocates ``(element_count + 1) * element_size`` bytes | ||
""" | ||
i8p = ir.IntType(8).as_pointer() | ||
i64 = ir.IntType(64) | ||
|
||
module = builder.module | ||
name = 'allocate_varlen_buffer' | ||
fnty = ir.FunctionType(i8p, [i64, i64]) | ||
fn = cgutils.get_or_insert_function(module, fnty, name) | ||
return builder.call(fn, [element_count, element_size]) |
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
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
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.