xobjects 0.5.1__tar.gz → 0.5.3__tar.gz
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.
- {xobjects-0.5.1/xobjects.egg-info → xobjects-0.5.3}/PKG-INFO +1 -1
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_buffer.py +30 -0
- xobjects-0.5.3/xobjects/_version.py +1 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/context.py +26 -2
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/context_cpu.py +5 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/context_cupy.py +4 -1
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/context_pyopencl.py +4 -0
- {xobjects-0.5.1 → xobjects-0.5.3/xobjects.egg-info}/PKG-INFO +1 -1
- xobjects-0.5.1/xobjects/_version.py +0 -1
- {xobjects-0.5.1 → xobjects-0.5.3}/LICENSE +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/pyproject.toml +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/setup.cfg +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/setup.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_align.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_array.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_capi.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_chunk.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_context_opencl.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_hybrid_class.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_kernel.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_linked_array.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_nplike_arrays.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_ref.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_scalars.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_shared_memory.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_strides.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_string.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_struct.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_to_json.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_typeutils.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/tests/test_unionref.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/__init__.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/_patch_pyopencl_array.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/array.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/capi.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/general.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/hybrid_class.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/linkedarray.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/ref.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/scalar.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/specialize_source.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/string.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/struct.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/test_helpers.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/typeutils.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects/union.py +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects.egg-info/SOURCES.txt +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects.egg-info/dependency_links.txt +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects.egg-info/requires.txt +0 -0
- {xobjects-0.5.1 → xobjects-0.5.3}/xobjects.egg-info/top_level.txt +0 -0
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
# ########################################### #
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
|
+
import pytest
|
|
7
8
|
|
|
8
9
|
import xobjects as xo
|
|
9
10
|
from xobjects.test_helpers import for_all_test_contexts, requires_context
|
|
@@ -94,6 +95,35 @@ def test_free_simple(test_context):
|
|
|
94
95
|
ch.free_string(offset)
|
|
95
96
|
ch.check()
|
|
96
97
|
|
|
98
|
+
@for_all_test_contexts
|
|
99
|
+
def test_free(test_context):
|
|
100
|
+
class CheckFree(xo.Struct):
|
|
101
|
+
a = xo.Float64
|
|
102
|
+
ch = CheckFree(a=5, _context=test_context)
|
|
103
|
+
assert ch._buffer.capacity == 8
|
|
104
|
+
assert ch._buffer.chunks == []
|
|
105
|
+
with pytest.raises(ValueError, match="Cannot free outside of buffer"):
|
|
106
|
+
ch._buffer.free(-2, 8)
|
|
107
|
+
with pytest.raises(ValueError, match="Cannot free outside of buffer"):
|
|
108
|
+
ch._buffer.free(0, 10)
|
|
109
|
+
with pytest.raises(ValueError, match="Cannot free outside of buffer"):
|
|
110
|
+
ch._buffer.free(7,2)
|
|
111
|
+
ch._buffer.free(0,4)
|
|
112
|
+
assert len(ch._buffer.chunks) == 1
|
|
113
|
+
assert ch._buffer.chunks[0].start == 0
|
|
114
|
+
assert ch._buffer.chunks[0].end == 4
|
|
115
|
+
ch._buffer.free(0,4) # Does nothing
|
|
116
|
+
ch._buffer.free(2,4) # Increases free chunk
|
|
117
|
+
assert len(ch._buffer.chunks) == 1
|
|
118
|
+
assert ch._buffer.chunks[0].start == 0
|
|
119
|
+
assert ch._buffer.chunks[0].end == 6
|
|
120
|
+
ch._buffer.free(7,1)
|
|
121
|
+
assert len(ch._buffer.chunks) == 2
|
|
122
|
+
assert ch._buffer.chunks[0].start == 0
|
|
123
|
+
assert ch._buffer.chunks[0].end == 6
|
|
124
|
+
assert ch._buffer.chunks[1].start == 7
|
|
125
|
+
assert ch._buffer.chunks[1].end == 8
|
|
126
|
+
|
|
97
127
|
|
|
98
128
|
@for_all_test_contexts
|
|
99
129
|
def test_grow(test_context):
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.5.3"
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
import logging
|
|
7
7
|
import os
|
|
8
8
|
import weakref
|
|
9
|
-
import xobjects as xo
|
|
10
9
|
from abc import ABC, abstractmethod
|
|
11
10
|
from collections import defaultdict
|
|
11
|
+
from importlib.metadata import entry_points
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
from typing import (
|
|
14
14
|
Dict,
|
|
@@ -354,6 +354,26 @@ class XContext(ABC):
|
|
|
354
354
|
) -> Dict[Tuple[str, tuple], KernelType]:
|
|
355
355
|
pass
|
|
356
356
|
|
|
357
|
+
def get_installed_c_source_paths(self) -> List[str]:
|
|
358
|
+
"""Returns a list of include paths registered in dependent packages.
|
|
359
|
+
|
|
360
|
+
In a package that depends on xobjects, you can register C source paths
|
|
361
|
+
using the entry point `xobjects.c_sources`. A path to the directory
|
|
362
|
+
containing the specified module will be added to the include path when
|
|
363
|
+
building kernels. For example, the following will allow to write
|
|
364
|
+
``#include <xtrack/path/to/some/header.h>`` in kernel sources:
|
|
365
|
+
|
|
366
|
+
.. code-block:: toml
|
|
367
|
+
[project.entry-points.xobjects]
|
|
368
|
+
include = "xtrack"
|
|
369
|
+
"""
|
|
370
|
+
sources = []
|
|
371
|
+
for ep in entry_points(group="xobjects", name="include"):
|
|
372
|
+
module = ep.load()
|
|
373
|
+
path = Path(module.__file__).parents[1]
|
|
374
|
+
sources.append(str(path))
|
|
375
|
+
return sources
|
|
376
|
+
|
|
357
377
|
@abstractmethod
|
|
358
378
|
def nparray_to_context_array(self, arr):
|
|
359
379
|
return arr
|
|
@@ -452,9 +472,13 @@ class XBuffer(ABC):
|
|
|
452
472
|
self.capacity = newcapacity
|
|
453
473
|
|
|
454
474
|
def free(self, offset, size):
|
|
475
|
+
if offset < 0 or offset + size > self.capacity:
|
|
476
|
+
raise ValueError("Cannot free outside of buffer")
|
|
455
477
|
nch = Chunk(offset, offset + size)
|
|
456
478
|
# insert sorted
|
|
457
|
-
if
|
|
479
|
+
if len(self.chunks) == 0:
|
|
480
|
+
self.chunks.append(nch)
|
|
481
|
+
elif offset > self.chunks[-1].start: # new chuck at the end
|
|
458
482
|
self.chunks.append(nch)
|
|
459
483
|
else: # new chuck needs to be inserted
|
|
460
484
|
for ic, ch in enumerate(self.chunks):
|
|
@@ -426,6 +426,11 @@ class ContextCpu(XContext):
|
|
|
426
426
|
xtr_compile_args.append("-DXO_CONTEXT_CPU_SERIAL")
|
|
427
427
|
xtr_link_args.append("-DXO_CONTEXT_CPU_SERIAL")
|
|
428
428
|
|
|
429
|
+
extra_include_paths = self.get_installed_c_source_paths()
|
|
430
|
+
include_flags = [f"-I{path}" for path in extra_include_paths]
|
|
431
|
+
xtr_compile_args.extend(include_flags)
|
|
432
|
+
xtr_link_args.extend(include_flags)
|
|
433
|
+
|
|
429
434
|
if os.name == "nt": # windows
|
|
430
435
|
# TODO: to be handled properly
|
|
431
436
|
xtr_compile_args = []
|
|
@@ -455,7 +455,10 @@ class ContextCupy(XContext):
|
|
|
455
455
|
with open(save_source_as, "w") as fid:
|
|
456
456
|
fid.write(specialized_source)
|
|
457
457
|
|
|
458
|
-
|
|
458
|
+
extra_include_paths = self.get_installed_c_source_paths()
|
|
459
|
+
include_flags = [f"-I{path}" for path in extra_include_paths]
|
|
460
|
+
extra_compile_args = (*extra_compile_args, *include_flags, "-DXO_CONTEXT_CUDA")
|
|
461
|
+
|
|
459
462
|
module = cupy.RawModule(
|
|
460
463
|
code=specialized_source, options=extra_compile_args
|
|
461
464
|
)
|
|
@@ -219,8 +219,12 @@ class ContextPyopencl(XContext):
|
|
|
219
219
|
with open(save_source_as, "w") as fid:
|
|
220
220
|
fid.write(specialized_source)
|
|
221
221
|
|
|
222
|
+
extra_include_paths = self.get_installed_c_source_paths()
|
|
223
|
+
include_flags = [f"-I{path}" for path in extra_include_paths]
|
|
224
|
+
|
|
222
225
|
extra_compile_args = (
|
|
223
226
|
*extra_compile_args,
|
|
227
|
+
*include_flags,
|
|
224
228
|
"-cl-std=CL2.0",
|
|
225
229
|
"-DXO_CONTEXT_CL",
|
|
226
230
|
)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.5.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|