Called by `setup.py`, it produces the generated code required by the virual machine. Generated files are indicated by the ``*_GENERATED.cpp`` suffix. Parameters ---------- body_stub The stub C++ source that the operation table is inserted into. header_stub
(body_stub: str='interp_body_stub.cpp', header_stub: str='interp_header_stub.hpp',
blocksize: Tuple[int]=(4096, 32), bounds_check: bool=True,
mkl: bool=False, C11: bool=True)
| 1362 | |
| 1363 | |
| 1364 | def generate(body_stub: str='interp_body_stub.cpp', header_stub: str='interp_header_stub.hpp', |
| 1365 | blocksize: Tuple[int]=(4096, 32), bounds_check: bool=True, |
| 1366 | mkl: bool=False, C11: bool=True) -> Tuple[OrderedDict, OrderedDict, List]: |
| 1367 | """ |
| 1368 | Called by `setup.py`, it produces the generated code required by the |
| 1369 | virual machine. Generated files are indicated by the ``*_GENERATED.cpp`` |
| 1370 | suffix. |
| 1371 | |
| 1372 | Parameters |
| 1373 | ---------- |
| 1374 | body_stub |
| 1375 | The stub C++ source that the operation table is inserted into. |
| 1376 | header_stub |
| 1377 | The stub C++ header that contains build-time specific macros, such as |
| 1378 | the desired block size for calculations. |
| 1379 | blocksize |
| 1380 | The tuple defines the number of elements (**not bytes**) each blocked |
| 1381 | operation loops over. The second integer is for reductions which are |
| 1382 | not currently implemented. |
| 1383 | bounds_check |
| 1384 | whether the C-code should conduct bounds checks on each blocked operation. |
| 1385 | The speed penalty for bounds checking is trivial. |
| 1386 | mkl |
| 1387 | Whether to link to the Intel MKL vector math library. **Presently not |
| 1388 | implemented.** |
| 1389 | C11 |
| 1390 | whether to include functions generally only found in `cmath.h` in |
| 1391 | C++11 compatible compilers. |
| 1392 | |
| 1393 | Returns |
| 1394 | ------- |
| 1395 | pythonTable: OrderedDict |
| 1396 | The hash table (dictionary) that ``necompiler3.py`` uses to map Python |
| 1397 | functions to codes for the virtual machine. The keys of `pythonTable` |
| 1398 | are tuples of the form `(id: Union[str,ast.AST], library: int, *dtypes: str)` |
| 1399 | `id` is either a `str`, such as ``'sin'`` or it can also be an ast node, |
| 1400 | such as ``ast.Add``. The library is one of the LIB enum values. Dtypes |
| 1401 | is ``numpy.dtype.chars`` that represent the (arg1, arg2, arg3) |
| 1402 | data types. The values of `pythonTable` are also tuples of the form |
| 1403 | `(opcode: bytes, return_dtype: str)`. This dictionary is written into |
| 1404 | a pickle file, ``lookup.pkl`` which is then packaged with the build. |
| 1405 | cTable: OrderedDict |
| 1406 | The cases for the jump table that the virtual machine, that is written |
| 1407 | into `body_stub`. e.g. ``(349, 'case 349: arcsin_ff( task_size, pc, params ); break;\n'),`` |
| 1408 | cFuncs: list |
| 1409 | The actual C-code for each function referenced in `cTable`, in order by |
| 1410 | op-code. This code is presently written into ``functions_GENERATED.cpp``. |
| 1411 | """ |
| 1412 | global INTERP_HEADER_DEFINES, BLOCKSIZE |
| 1413 | |
| 1414 | # Set globals for passing blocksize to variables. |
| 1415 | # Not sure what blocksize[1] is actually used for in NumExpr2 |
| 1416 | BLOCKSIZE = blocksize[0] |
| 1417 | |
| 1418 | INTERP_HEADER_DEFINES= "".join([INTERP_HEADER_DEFINES, |
| 1419 | '#define BLOCK_SIZE1 {}\n'.format(blocksize[0]), |
| 1420 | '#define BLOCK_SIZE2 {}\n'.format(blocksize[1])]) |
| 1421 |
no test coverage detected
searching dependent graphs…