Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
baee891
MNT: move interned strings into a single global struct
ngoldbaum May 30, 2024
69075c1
MNT: move cached imports into a global struct
ngoldbaum May 21, 2024
e5c1bd6
MNT: move cpu dispatch registry into global data struct
ngoldbaum May 30, 2024
7719cf2
MNT: move ndarray.__array_*__ references to global data struct
ngoldbaum May 30, 2024
3cbb68d
MNT: move sys.flags.optimize cache to global data struct
ngoldbaum May 30, 2024
2ffcc71
MNT: set up tuple for truediv in global data struct
ngoldbaum May 30, 2024
d2ca21b
MNT: move unpack_bits LUT into global static struct
ngoldbaum May 30, 2024
a1f7200
MNT: move references to int(1) and int(0) to global static struct
ngoldbaum May 30, 2024
26c243d
MNT: move initialization of global ArrayMethods to module initialization
ngoldbaum May 30, 2024
536e5fb
MNT: move initialization of global tuples to global data struct
ngoldbaum May 30, 2024
0c22126
MNT: move default extobj contextvar to global data dict
ngoldbaum May 30, 2024
90b1f38
MNT: move PyArray_SetStringFunction internals into global data struct
ngoldbaum May 30, 2024
6a296c4
BUG: remove questionable static initialization of an array object
ngoldbaum May 30, 2024
398f095
MNT: split global data struct into two structs
ngoldbaum Jun 3, 2024
8f84875
MNT: add PyArrayMethodObject caches to static data struct
ngoldbaum Jun 5, 2024
402a83c
MNT: move some thread-unsafe state in thread-unsafe state struct
ngoldbaum Jun 5, 2024
e43275a
MNT: make data structs static instead of heap-allocated
ngoldbaum Jun 5, 2024
b706536
MNT: apply sebastian's refactoring suggestions
ngoldbaum Jun 6, 2024
c237038
MNT: move static data structs into their own file
ngoldbaum Jun 7, 2024
98ae65d
MNT: Add more global state I missed to the thread_unsafe_state struct
ngoldbaum Jun 7, 2024
a334ddc
MNT: verify all entries in npy_interned_str and npy_static_pydata are…
ngoldbaum Jun 11, 2024
9ed317f
Apply suggestions from code review
ngoldbaum Jun 13, 2024
3ae66b1
MAINT: apply more of Sebastian's suggestions
ngoldbaum Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MNT: move cpu dispatch registry into global data struct
  • Loading branch information
ngoldbaum committed Jun 19, 2024
commit e5c1bd62b4ab92ac8aa47f4b2806c2dc2c109170
15 changes: 9 additions & 6 deletions numpy/_core/src/common/npy_cpu_dispatch.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include "npy_cpu_dispatch.h"
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE

static PyObject *npy__cpu_dispatch_registery = NULL;
#include "npy_cpu_dispatch.h"
#include "numpy/ndarraytypes.h"
#include "multiarraymodule.h"

NPY_VISIBILITY_HIDDEN int
npy_cpu_dispatch_tracer_init(PyObject *mod)
{
if (npy__cpu_dispatch_registery != NULL) {
if (npy_ma_global_data->cpu_dispatch_registry != NULL) {
PyErr_Format(PyExc_RuntimeError, "CPU dispatcher tracer already initlized");
return -1;
}
Expand All @@ -22,21 +25,21 @@ npy_cpu_dispatch_tracer_init(PyObject *mod)
if (err != 0) {
return -1;
}
npy__cpu_dispatch_registery = reg_dict;
npy_ma_global_data->cpu_dispatch_registry = reg_dict;
return 0;
}

NPY_VISIBILITY_HIDDEN void
npy_cpu_dispatch_trace(const char *fname, const char *signature,
const char **dispatch_info)
{
PyObject *func_dict = PyDict_GetItemString(npy__cpu_dispatch_registery, fname);
PyObject *func_dict = PyDict_GetItemString(npy_ma_global_data->cpu_dispatch_registry, fname);
if (func_dict == NULL) {
func_dict = PyDict_New();
if (func_dict == NULL) {
return;
}
int err = PyDict_SetItemString(npy__cpu_dispatch_registery, fname, func_dict);
int err = PyDict_SetItemString(npy_ma_global_data->cpu_dispatch_registry, fname, func_dict);
Py_DECREF(func_dict);
if (err != 0) {
return;
Expand Down
5 changes: 5 additions & 0 deletions numpy/_core/src/common/npy_cpu_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

/******************** Private Definitions *********************/

// This is initialized during module initialization and thereafter immutable.
// We don't include it in the global data struct because the definitions in
// this file are shared by the _simd, _umath_tests, and
// _multiarray_umath modules

// Hold all CPU features boolean values
static unsigned char npy__cpu_have[NPY_CPU_FEATURE_MAX];

Expand Down
7 changes: 7 additions & 0 deletions numpy/_core/src/multiarray/multiarraymodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ typedef struct npy_ma_global_data_struct {
PyObject *os_PathLike;
PyObject *os_fspath;

/*
* Used for CPU feature detection and dispatch
*
* Filled in during module initialization and thereafter immutable
*/
PyObject *cpu_dispatch_registry;

/*
* The following entries store cached references to object obtained
* via an import. All of these are initialized at runtime by
Expand Down