xobjects 0.5.12__tar.gz → 0.5.14__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.
Files changed (57) hide show
  1. {xobjects-0.5.12/xobjects.egg-info → xobjects-0.5.14}/PKG-INFO +1 -1
  2. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_capi.py +1 -3
  3. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_common.py +2 -4
  4. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_kernel.py +2 -4
  5. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_ref.py +6 -12
  6. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_shared_memory.py +3 -5
  7. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_struct.py +4 -8
  8. xobjects-0.5.14/xobjects/_version.py +1 -0
  9. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/capi.py +2 -4
  10. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/context_cpu.py +17 -9
  11. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/context_cupy.py +11 -6
  12. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/context_pyopencl.py +2 -4
  13. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/headers/atomicadd.h +11 -2
  14. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/scalar.py +0 -1
  15. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/struct.py +27 -0
  16. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/test_helpers.py +8 -0
  17. {xobjects-0.5.12 → xobjects-0.5.14/xobjects.egg-info}/PKG-INFO +1 -1
  18. xobjects-0.5.12/xobjects/_version.py +0 -1
  19. {xobjects-0.5.12 → xobjects-0.5.14}/Architecture.md +0 -0
  20. {xobjects-0.5.12 → xobjects-0.5.14}/LICENSE +0 -0
  21. {xobjects-0.5.12 → xobjects-0.5.14}/MANIFEST.in +0 -0
  22. {xobjects-0.5.12 → xobjects-0.5.14}/Readme.md +0 -0
  23. {xobjects-0.5.12 → xobjects-0.5.14}/pyproject.toml +0 -0
  24. {xobjects-0.5.12 → xobjects-0.5.14}/setup.cfg +0 -0
  25. {xobjects-0.5.12 → xobjects-0.5.14}/setup.py +0 -0
  26. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_align.py +0 -0
  27. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_array.py +0 -0
  28. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_buffer.py +0 -0
  29. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_chunk.py +0 -0
  30. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_context_opencl.py +0 -0
  31. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_hybrid_class.py +0 -0
  32. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_linked_array.py +0 -0
  33. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_nplike_arrays.py +0 -0
  34. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_scalars.py +0 -0
  35. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_strides.py +0 -0
  36. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_string.py +0 -0
  37. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_to_dict.py +0 -0
  38. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_typeutils.py +0 -0
  39. {xobjects-0.5.12 → xobjects-0.5.14}/tests/test_unionref.py +0 -0
  40. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/__init__.py +0 -0
  41. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/_patch_pyopencl_array.py +0 -0
  42. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/array.py +0 -0
  43. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/context.py +0 -0
  44. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/general.py +0 -0
  45. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/headers/common.h +0 -0
  46. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/hybrid_class.py +0 -0
  47. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/linkedarray.py +0 -0
  48. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/ref.py +0 -0
  49. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/specialize_source.py +0 -0
  50. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/string.py +0 -0
  51. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/typeutils.py +0 -0
  52. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects/union.py +0 -0
  53. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects.egg-info/SOURCES.txt +0 -0
  54. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects.egg-info/dependency_links.txt +0 -0
  55. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects.egg-info/entry_points.txt +0 -0
  56. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects.egg-info/requires.txt +0 -0
  57. {xobjects-0.5.12 → xobjects-0.5.14}/xobjects.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xobjects
3
- Version: 0.5.12
3
+ Version: 0.5.14
4
4
  Summary: In-memory serialization and code generator for CPU and GPU
5
5
  Home-page: https://xsuite.readthedocs.io/
6
6
  Download-URL: https://pypi.python.org/pypi/xobjects
@@ -179,9 +179,7 @@ def test_array_get_shape(test_context, array_type):
179
179
  *out_nd = ARRAY_TYPE_nd(arr);
180
180
  ARRAY_TYPE_shape(arr, out_shape);
181
181
  }
182
- """.replace(
183
- "ARRAY_TYPE", array_type.__name__
184
- )
182
+ """.replace("ARRAY_TYPE", array_type.__name__)
185
183
 
186
184
  kernels = {
187
185
  "get_nd_and_shape": xo.Kernel(
@@ -87,8 +87,7 @@ def test_atomic(overload, ctype, test_context):
87
87
 
88
88
  class TestAtomic(xo.Struct):
89
89
  val = ctype
90
- _extra_c_sources = [
91
- f"""
90
+ _extra_c_sources = [f"""
92
91
  #include "xobjects/headers/common.h"
93
92
  #include "xobjects/headers/atomicadd.h"
94
93
 
@@ -101,8 +100,7 @@ def test_atomic(overload, ctype, test_context):
101
100
  retvals[ii] = ret;
102
101
  END_VECTORIZE;
103
102
  }}
104
- """
105
- ]
103
+ """]
106
104
 
107
105
  kernels = {
108
106
  "run_atomic_test": xo.Kernel(
@@ -216,15 +216,13 @@ def test_kernels_save_load_with_classes(tmp_path, mocker):
216
216
  "x": xo.Float64,
217
217
  "y": xo.Float64,
218
218
  }
219
- _extra_c_sources = [
220
- """
219
+ _extra_c_sources = ["""
221
220
  /*gpufun*/ double myfun(TestClassData tc){
222
221
  double x = TestClassData_get_x(tc);
223
222
  double y = TestClassData_get_y(tc);
224
223
  return x * y;
225
224
  }
226
- """
227
- ]
225
+ """]
228
226
  _kernels = {
229
227
  "myfun": xo.Kernel(
230
228
  args=[
@@ -220,29 +220,25 @@ def test_unionref(test_context):
220
220
  b = xo.Float64
221
221
  h = xo.Float64
222
222
 
223
- _extra_c_sources = [
224
- """
223
+ _extra_c_sources = ["""
225
224
  /*gpufun*/
226
225
  double Triangle_compute_area(Triangle tr, double scale){
227
226
  double b = Triangle_get_b(tr);
228
227
  double h = Triangle_get_h(tr);
229
228
  return 0.5*b*h*scale;
230
229
  }
231
- """
232
- ]
230
+ """]
233
231
 
234
232
  class Square(xo.Struct):
235
233
  a = xo.Float64
236
234
 
237
- _extra_c_sources = [
238
- """
235
+ _extra_c_sources = ["""
239
236
  /*gpufun*/
240
237
  double Square_compute_area(Square sq, double scale){
241
238
  double a = Square_get_a(sq);
242
239
  return a*a*scale;
243
240
  }
244
- """
245
- ]
241
+ """]
246
242
 
247
243
  class Base(xo.UnionRef):
248
244
  _reftypes = (Triangle, Square)
@@ -259,8 +255,7 @@ def test_unionref(test_context):
259
255
  height = xo.Float64
260
256
  volume = xo.Float64
261
257
 
262
- _extra_c_sources = [
263
- """
258
+ _extra_c_sources = ["""
264
259
  /*gpukern*/
265
260
  void Prism_compute_volume(Prism pr){
266
261
  Base base = Prism_getp_base(pr);
@@ -269,8 +264,7 @@ def test_unionref(test_context):
269
264
  printf("base_area = %e", base_area);
270
265
  Prism_set_volume(pr, base_area*height);
271
266
  }
272
- """
273
- ]
267
+ """]
274
268
 
275
269
  test_context.add_kernels(
276
270
  kernels={
@@ -35,8 +35,7 @@ def test_shared_memory():
35
35
 
36
36
  class TestElement(xo.HybridClass):
37
37
  _xofields = {}
38
- _extra_c_sources = [
39
- """
38
+ _extra_c_sources = ["""
40
39
  __global__ void test_shared_memory(const double* input_arr, double* result, const int n) {
41
40
  // simple kernel to test shared memory
42
41
  // reduction with an array of 4 doubles using 2 blocks each 2 threads
@@ -47,7 +46,7 @@ def test_shared_memory():
47
46
  unsigned int gid = blockIdx.x*blockDim.x + threadIdx.x; // global thread ID: 0,1,2,3
48
47
 
49
48
  // init shared memory with chunk of input array
50
- extern __shared__ double sdata[2];
49
+ extern __shared__ double sdata[];
51
50
  sdata[tid] = input_arr[gid];
52
51
  __syncthreads();
53
52
 
@@ -59,8 +58,7 @@ def test_shared_memory():
59
58
  atomicAdd(&result[tid], sdata[tid]);
60
59
  }
61
60
  }
62
- """
63
- ]
61
+ """]
64
62
  _kernels = _test_shared_memory_kernels
65
63
 
66
64
  def __init__(
@@ -222,8 +222,7 @@ def test_kernel_namings():
222
222
  var_mult_3 = xo.Float64[:]
223
223
  var_mult_4 = xo.Float64[:]
224
224
 
225
- _extra_c_sources = [
226
- r"""
225
+ _extra_c_sources = [r"""
227
226
  double mul(MyStruct stru) {
228
227
  int32_t n = MyStruct_get_n(stru);
229
228
  double* var_mult_1 = MyStruct_getp1_var_mult_1(stru, 0);
@@ -258,8 +257,7 @@ double mult_four(MyStruct stru) {
258
257
  y+= var_mult_1[tid] * var_mult_2[tid] * var_mult_3[tid] * var_mult_4[tid];
259
258
  }
260
259
  return y;
261
- }"""
262
- ]
260
+ }"""]
263
261
 
264
262
  kernel_descriptions = {
265
263
  "mul": xo.Kernel(
@@ -316,15 +314,13 @@ def test_compile_kernels_only_if_needed(tmp_path, mocker):
316
314
  "x": xo.Float64,
317
315
  "y": xo.Float64,
318
316
  }
319
- _extra_c_sources = [
320
- """
317
+ _extra_c_sources = ["""
321
318
  /*gpufun*/ double myfun(TestClassData tc){
322
319
  double x = TestClassData_get_x(tc);
323
320
  double y = TestClassData_get_y(tc);
324
321
  return x * y;
325
322
  }
326
- """
327
- ]
323
+ """]
328
324
  _kernels = {
329
325
  "myfun": xo.Kernel(
330
326
  args=[
@@ -0,0 +1 @@
1
+ __version__ = "0.5.14"
@@ -525,14 +525,12 @@ def gen_method_switch(cls, path, conf, method):
525
525
  for arg in kernel.args[1:]:
526
526
  targs.append(f"{arg.name}")
527
527
  targs = ",".join(targs)
528
- lst.append(
529
- f"""\
528
+ lst.append(f"""\
530
529
  #ifndef {refname.upper()}_SKIP_{atname.upper()}
531
530
  case {refname}_{atname}_t:
532
531
  return {atname}_{method.c_name}({targs});
533
532
  break;
534
- #endif"""
535
- )
533
+ #endif""")
536
534
  lst.append(" }")
537
535
  lst.append(f" return{'' if method.ret is None else ' 0'};")
538
536
  lst.append("}")
@@ -316,6 +316,12 @@ class ContextCpu(XContext):
316
316
  if _forbid_compile:
317
317
  raise RuntimeError("Compilation is forbidden")
318
318
 
319
+ if os.environ.get('XOBJECTS_FORBID_COMPILE'):
320
+ raise RuntimeError(
321
+ "Compilation is forbidden by the environment variable "
322
+ "XOBJECTS_FORBID_COMPILE"
323
+ )
324
+
319
325
  so_file = self.compile_kernel(
320
326
  module_name,
321
327
  kernel_descriptions,
@@ -376,8 +382,9 @@ class ContextCpu(XContext):
376
382
  )
377
383
  out_kernels = {}
378
384
  for pyname, kernel_desc in kernel_descriptions.items():
385
+ c_name = kernel_desc.c_name or pyname
379
386
  out_kernels[pyname] = KernelCpu(
380
- function=getattr(module.lib, kernel_desc.c_name),
387
+ function=getattr(module.lib, c_name),
381
388
  description=kernel_desc,
382
389
  ffi_interface=module.ffi,
383
390
  context=self,
@@ -459,14 +466,15 @@ class ContextCpu(XContext):
459
466
  return Path(output_file)
460
467
  finally:
461
468
  # Clean temp files
462
- files_to_remove = [
463
- module_name + ".c",
464
- module_name + ".o",
465
- ]
466
-
467
- for ff in files_to_remove:
468
- if os.path.exists(ff):
469
- os.remove(ff)
469
+ if 'XOBJECTS_KEEP_BUILD_FILES' not in os.environ:
470
+ files_to_remove = [
471
+ module_name + ".c",
472
+ module_name + ".o",
473
+ ]
474
+
475
+ for ff in files_to_remove:
476
+ if os.path.exists(ff):
477
+ os.remove(ff)
470
478
 
471
479
  def _build_sources(
472
480
  self,
@@ -350,19 +350,24 @@ if _enabled:
350
350
  return cupy.ndarray.__invert__(self._as_cupy())
351
351
 
352
352
 
353
- cudaheader: List[SourceType] = [
354
- """\
355
- typedef signed long long int64_t; //only_for_context cuda
353
+ cudaheader: List[SourceType] = ["""\
356
354
  typedef signed int int32_t; //only_for_context cuda
357
355
  typedef signed short int16_t; //only_for_context cuda
358
356
  typedef signed char int8_t; //only_for_context cuda
359
- typedef unsigned long long uint64_t; //only_for_context cuda
360
357
  typedef unsigned int uint32_t; //only_for_context cuda
361
358
  typedef unsigned short uint16_t; //only_for_context cuda
362
359
  typedef unsigned char uint8_t; //only_for_context cuda
363
360
 
364
- """
365
- ]
361
+ #if defined(__CUDACC__) || defined(__HIPCC_RTC__)
362
+ typedef signed long long int64_t;
363
+ typedef unsigned long long uint64_t;
364
+ #endif
365
+
366
+ #ifndef NULL
367
+ #define NULL nullptr
368
+ #endif
369
+
370
+ """]
366
371
 
367
372
 
368
373
  def nplike_to_cupy(arr):
@@ -44,8 +44,7 @@ except ImportError:
44
44
 
45
45
  from ._patch_pyopencl_array import _patch_pyopencl_array
46
46
 
47
- openclheader: List[SourceType] = [
48
- """\
47
+ openclheader: List[SourceType] = ["""\
49
48
  #ifndef XOBJ_STDINT
50
49
  typedef long int64_t;
51
50
  typedef int int32_t;
@@ -59,8 +58,7 @@ typedef unsigned char uint8_t;
59
58
  #ifndef NULL
60
59
  #define NULL 0L
61
60
  #endif
62
- """
63
- ]
61
+ """]
64
62
 
65
63
  if _enabled:
66
64
  # order of base classes matters as it defines which __setitem__ is used
@@ -101,8 +101,9 @@ DEF_ATOMIC_ADD(double , f64)
101
101
  // -------------------------------------------
102
102
  #if defined(XO_CONTEXT_CUDA)
103
103
  // CUDA compiler may not have <stdint.h>, so define the types if needed.
104
- #ifdef __CUDACC_RTC__
105
- // NVRTC (CuPy RawModule default) can’t see <stdint.h>, so detect it via __CUDACC_RTC__
104
+ #if defined(__CUDACC_RTC__) || defined(__HIPCC_RTC__)
105
+ // NVRTC and HIPRTC (CuPy RawModule default) can’t see <stdint.h>
106
+ // We detect via __CUDACC_RTC__ (Nvidia) or __HIPCC_RTC__ (ROCm)
106
107
  typedef signed char int8_t;
107
108
  typedef short int16_t;
108
109
  typedef int int32_t;
@@ -111,6 +112,14 @@ DEF_ATOMIC_ADD(double , f64)
111
112
  typedef unsigned short uint16_t;
112
113
  typedef unsigned int uint32_t;
113
114
  typedef unsigned long long uint64_t;
115
+ #elif defined(__HIPCC__) && !defined(__HIPCC_RTC__)
116
+ // ROCm-HIPCC compiler appears to have definitions for 64-bit int types
117
+ typedef signed char int8_t;
118
+ typedef short int16_t;
119
+ typedef int int32_t;
120
+ typedef unsigned char uint8_t;
121
+ typedef unsigned short uint16_t;
122
+ typedef unsigned int uint32_t;
114
123
  #else
115
124
  // Alternatively, NVCC path is fine with host headers
116
125
  #include <stdint.h>
@@ -14,7 +14,6 @@ import numpy as np
14
14
  import logging
15
15
  from .typeutils import Info
16
16
 
17
-
18
17
  log = logging.getLogger(__name__)
19
18
 
20
19
 
@@ -45,6 +45,7 @@ Field instance:
45
45
 
46
46
 
47
47
  """
48
+
48
49
  import logging
49
50
  from typing import Callable, Optional
50
51
 
@@ -475,6 +476,32 @@ class Struct(metaclass=MetaStruct):
475
476
  extra_classes=(),
476
477
  extra_compile_args=(),
477
478
  ):
479
+
480
+ if context.allow_prebuilt_kernels:
481
+ _print_state = Print.suppress
482
+ Print.suppress = True
483
+ try:
484
+ from xsuite import (
485
+ get_suitable_kernel,
486
+ XSK_PREBUILT_KERNELS_LOCATION,
487
+ )
488
+ kernel_info = get_suitable_kernel(
489
+ config={},
490
+ tracker_element_classes=[],
491
+ classes=list(extra_classes) + [cls],
492
+ )
493
+ except ImportError:
494
+ kernel_info = None
495
+
496
+ Print.suppress = _print_state
497
+ if kernel_info:
498
+ kernels = context.kernels_from_file(
499
+ module_name=kernel_info['module_name'],
500
+ containing_dir=XSK_PREBUILT_KERNELS_LOCATION,
501
+ kernel_descriptions=cls._kernels,
502
+ )
503
+ context.kernels.update(kernels)
504
+
478
505
  if only_if_needed:
479
506
  all_found = True
480
507
  for kk, kernel_description in cls._kernels.items():
@@ -5,6 +5,7 @@
5
5
 
6
6
  from functools import wraps
7
7
  from typing import Callable, Iterable, Union
8
+ import os
8
9
 
9
10
  import pytest
10
11
 
@@ -105,3 +106,10 @@ def fix_random_seed(seed: int):
105
106
  return wrapper
106
107
 
107
108
  return decorator
109
+
110
+ def skip_if_forbid_compile():
111
+ if os.environ.get('XOBJECTS_FORBID_COMPILE'):
112
+ pytest.skip(
113
+ "Compilation is forbidden by the environment variable "
114
+ "XOBJECTS_FORBID_COMPILE"
115
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xobjects
3
- Version: 0.5.12
3
+ Version: 0.5.14
4
4
  Summary: In-memory serialization and code generator for CPU and GPU
5
5
  Home-page: https://xsuite.readthedocs.io/
6
6
  Download-URL: https://pypi.python.org/pypi/xobjects
@@ -1 +0,0 @@
1
- __version__ = "0.5.12"
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