edsger 0.1.1__cp39-cp39-macosx_11_0_arm64.whl → 0.1.2__cp39-cp39-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
edsger/dijkstra.pyx CHANGED
@@ -23,6 +23,11 @@ from edsger.commons cimport (
23
23
  DTYPE_INF, UNLABELED, SCANNED, DTYPE_t, ElementState)
24
24
  cimport edsger.pq_4ary_dec_0b as pq # priority queue
25
25
 
26
+ # Memory prefetching support (x86/x64 only)
27
+ cdef extern from "prefetch_compat.h":
28
+ void prefetch_hint(char*, int) nogil
29
+ int PREFETCH_T0
30
+
26
31
 
27
32
  cpdef cnp.ndarray compute_sssp(
28
33
  cnp.uint32_t[::1] csr_indptr,
@@ -83,8 +88,17 @@ cpdef cnp.ndarray compute_sssp(
83
88
  <size_t>csr_indptr[tail_vert_idx + 1]):
84
89
 
85
90
  head_vert_idx = <size_t>csr_indices[idx]
91
+
92
+ # Prefetch next iteration data to improve cache performance
93
+ if idx + 1 < <size_t>csr_indptr[tail_vert_idx + 1]:
94
+ prefetch_hint(<char*>&csr_indices[idx + 1], PREFETCH_T0)
95
+ prefetch_hint(<char*>&csr_data[idx + 1], PREFETCH_T0)
96
+
86
97
  vert_state = pqueue.Elements[head_vert_idx].state
87
98
  if vert_state != SCANNED:
99
+ # Prefetch priority queue element data for the vertex
100
+ prefetch_hint(<char*>&pqueue.Elements[head_vert_idx], PREFETCH_T0)
101
+
88
102
  head_vert_val = tail_vert_val + csr_data[idx]
89
103
  if vert_state == UNLABELED:
90
104
  pq.insert(&pqueue, head_vert_idx, head_vert_val)
@@ -164,8 +178,17 @@ cpdef cnp.ndarray compute_sssp_w_path(
164
178
  <size_t>csr_indptr[tail_vert_idx + 1]):
165
179
 
166
180
  head_vert_idx = <size_t>csr_indices[idx]
181
+
182
+ # Prefetch next iteration data to improve cache performance
183
+ if idx + 1 < <size_t>csr_indptr[tail_vert_idx + 1]:
184
+ prefetch_hint(<char*>&csr_indices[idx + 1], PREFETCH_T0)
185
+ prefetch_hint(<char*>&csr_data[idx + 1], PREFETCH_T0)
186
+
167
187
  vert_state = pqueue.Elements[head_vert_idx].state
168
188
  if vert_state != SCANNED:
189
+ # Prefetch priority queue element data for the vertex
190
+ prefetch_hint(<char*>&pqueue.Elements[head_vert_idx], PREFETCH_T0)
191
+
169
192
  head_vert_val = tail_vert_val + csr_data[idx]
170
193
  if vert_state == UNLABELED:
171
194
  pq.insert(&pqueue, head_vert_idx, head_vert_val)