Repository navigation
Commit 8b20f77
authored
* cuda.core.texture: rename from_array -> from_opaque_array, element_size -> element_bytes (#2292)
Addresses items 5 and 7 of the pre-v1.1.0 texture API-style review.
- ResourceDescriptor.from_array -> ResourceDescriptor.from_opaque_array:
the Array -> OpaqueArray rename removed "array" ambiguity, so the factory
name should follow suit.
- OpaqueArray.element_size -> OpaqueArray.element_bytes: the accessor returns
a byte count, matching the _bytes convention already used by size_bytes and
pitch_bytes.
Both are renames of APIs not yet released (first ship in v1.1.0), so no
deprecation shim is needed; the new names carry a versionadded:: 1.1.0 note.
Call sites in the texture tests and the four texture examples are updated.
* cuda.core.texture: move texture enums to cuda.core.typing as StrEnum (#2292)
Addresses item 4 of the pre-v1.1.0 texture API-style review.
The texture/surface enums were IntEnum subclasses backed by cydriver.CU_*
values, defined in the cuda.core.texture root namespace and lacking the Type
suffix. Every other cuda.core enum unified pre-1.0 lives in cuda.core.typing
as a StrEnum with semantic string values and a Type suffix. Bring the texture
enums in line:
- ArrayFormat -> cuda.core.typing.ArrayFormatType
- AddressMode -> cuda.core.typing.AddressModeType
- FilterMode -> cuda.core.typing.FilterModeType
- ReadMode -> cuda.core.typing.ReadModeType
Internally the driver integer values are still needed, so _array and _texture
carry private CU<->StrEnum bridge maps; OpaqueArray/MipmappedArray keep storing
the driver int and convert on the .format boundary. Per the enum convention,
plain strings are accepted anywhere an enum is expected (via _normalize_enum /
_normalize_array_format), and invalid values raise ValueError. TextureDescriptor
gains a __post_init__ that normalizes its filter_mode/read_mode/
mipmap_filter_mode fields at construction.
Enums are dropped from the cuda.core.texture __all__ and documented under
cuda.core.typing. Tests, examples, and docs are updated to the new names; the
negative-path tests that previously expected a TypeError at texture creation
now expect a ValueError at descriptor construction.
* cuda.core.texture: accept NumPy dtypes for array format (#2292)
Addresses item 3 of the pre-v1.1.0 texture API-style review.
TensorMapDescriptorOptions.data_type already accepts NumPy dtype objects and
keeps its enum as a fallback. Apply the same precedent to the texture format
argument: OpaqueArray / MipmappedArray creation and
ResourceDescriptor.from_linear / from_pitch2d now accept an ArrayFormatType,
a plain str, or a NumPy dtype object (anything numpy.dtype() accepts).
Each ArrayFormatType value is already spelled as a NumPy dtype name, so the
eight formats map 1:1 via a new _NUMPY_DTYPE_TO_ARRAYFORMAT table. All four
factories funnel through _validate_format_channels -> _normalize_array_format,
so dtype support is added in one place. ml_dtypes is intentionally not imported:
every current format is a standard NumPy dtype, and the ml_dtypes path only
becomes relevant if/when a bfloat16 format is added.
* cuda.core.texture: rename TextureDescriptor -> TextureObjectOptions (#2292)
Addresses the rename portion of item 2 of the pre-v1.1.0 texture API-style
review.
CUDA_TEXTURE_DESC is pure creation input (it cannot be queried back from a
texture object), so "descriptor" borrowed the driver naming inappropriately.
TextureObjectOptions matches the XxxOptions convention used throughout
cuda.core (StreamOptions, EventOptions, TensorMapDescriptorOptions, ...).
Pure rename of the dataclass and all references across the implementation,
stubs, __init__ __all__, docs, tests, and examples. The from_descriptor
texture_descriptor= keyword is left untouched here; the whole creation entry
point is replaced by Device.create_texture_object(*, resource, options) in a
later commit.
* cuda.core.texture: add Device.create_opaque_array / create_mipmapped_array (#2292)
Addresses item 1 (array allocation) and item 2 (Options dataclasses) of the
pre-v1.1.0 texture API-style review.
Every other user-allocatable resource in cuda.core is created via Device.create_*
(create_stream, create_event, ...) with an XxxOptions dataclass. The texture
arrays used per-type classmethod factories (OpaqueArray.from_descriptor,
MipmappedArray.from_descriptor) with loose kwargs instead. Move them in line:
- add OpaqueArrayOptions and MipmappedArrayOptions dataclasses (validated in
__post_init__, mirroring TensorMapDescriptorOptions);
- add Device.create_opaque_array(options) and Device.create_mipmapped_array(
options), which gate on _check_context_initialized() and delegate to private
module factories that bind to the current device (same pattern as
create_event / create_graph_builder);
- remove the OpaqueArray.from_descriptor / MipmappedArray.from_descriptor
classmethods; the private _from_handle graphics-interop path is retained.
New entry points carry versionadded:: 1.1.0. Options are exported from
cuda.core.texture and documented in api.rst. Tests and the texture examples are
updated to Device().create_*_array(<Options>(...)).
* cuda.core.texture: add Device.create_texture_object / create_surface_object (#2292)
Addresses item 1 (object creation) and item 6 (drop SurfaceObject.from_array
sugar) of the pre-v1.1.0 texture API-style review, completing the move to the
Device.create_* allocation shape.
- add Device.create_texture_object(*, resource, options) and
Device.create_surface_object(*, resource), gating on
_check_context_initialized() and delegating to private module factories that
bind to the current device (same pattern as create_opaque_array);
- remove TextureObject.from_descriptor, SurfaceObject.from_descriptor, and the
speculative SurfaceObject.from_array sugar (a surface is now built from an
explicit ResourceDescriptor.from_opaque_array(...) like every other backing);
- rename the sampling-options argument from texture_descriptor to options on the
new entry point, matching the create_* + XxxOptions convention (the queryable
TextureObject.texture_descriptor property is unchanged).
New entry points carry versionadded:: 1.1.0. Tests, examples, and api.rst are
updated; a make_surface() helper mirrors make_texture() in the fluid example.
* cuda.core.texture: apply pre-commit (ruff, ruff-format, stubgen) (#2292)
Mechanical pre-commit pass over the #2292 texture API series:
- ruff: drop now-unused imports in the texture example/test files and remove an
unused _normalize_array_format import from _texture.pyx (cython-lint);
- ruff-format: reflow the rewritten call sites in the tests and examples;
- stubgen-pyx: regenerate the .pyi stubs from the updated .pyx sources.
* cuda.core.texture: address API-review follow-ups (#2292)
Apply the review findings from the texture API-style follow-up:
- Rename TextureObject.texture_descriptor -> options (and the internal
_texture_desc slot -> _options) to drop the borrowed "descriptor"
naming, matching the TextureObjectOptions rename.
- Make options a required argument on create_opaque_array /
create_mipmapped_array (shape/format/num_channels have no defaults),
so omitting it raises a clear error instead of a raw dataclass
TypeError. create_texture_object keeps options=None (all-default
sampling state).
- Add return and resource/options type annotations to the four
Device.create_* texture factories via a TYPE_CHECKING texture import
(mirroring the existing GraphBuilder pattern).
- Clarify in the create_* docstrings that the resource is created in the
current CUDA context (call set_current first), mirroring
create_stream / create_event.
- Add versionadded:: 1.1.0 to OpaqueArrayOptions, MipmappedArrayOptions,
TextureObjectOptions, and the new options property.
- Fix a stale negative-path test whose regex no longer matched the
shared check_or_create_options message; rename stale from_descriptor
test names to create_*; realign the gl_interop_fluid API-MAP comment
table after the enum renames.
- Regenerate .pyi stubs.
* cuda.core.texture: fix stale address_mode entry-rejection test (#2292)
The StrEnum migration (item 4 of #2292) makes a plain str acceptable
anywhere an AddressModeType is expected. A bad tuple entry like "bad" is
therefore a valid *type* but an invalid *value*, so _normalize_enum
rejects it with a ValueError (naming the offending position
address_mode[1]), not a TypeError. Update the test to assert ValueError
and rename it to test_address_mode_rejects_invalid_entry. This is the
second of the two CI failures on PR #2307; the first (the stale
options-type message) was fixed in the previous commit.
* cuda.core.texture: register new StrEnums in enum-coverage test (#2292)
test_enum_coverage.py::test_all_str_enums_in_cases requires every
StrEnum in cuda.core to be declared either in _CASES (bound to a
cuda_binding enum) or in _UNBOUND_STR_ENUMS. The four texture enums
moved into cuda.core.typing (item 4 of #2292) were not registered,
failing that guard.
- AddressModeType / FilterModeType are 1:1 wrappers of CUaddress_mode /
CUfilter_mode, so add mapping=None _CASES entries (count-check only;
the texture mapping dicts store cydriver-derived ints, not
driver.<Enum> members, so the isinstance-based mapping check does not
apply).
- ArrayFormatType exposes only the 8 NumPy-representable formats out of
CUarray_format's ~67 members, so it is a curated subset rather than a
1:1 wrapper -> _UNBOUND_STR_ENUMS.
- ReadModeType maps to the CU_TRSF_READ_AS_INTEGER flag bit, not a
CUenum -> _UNBOUND_STR_ENUMS.
This is the third local test failure; the other two (stale texture
negative-path tests) were fixed in the two preceding commits.
* cuda.core.texture: add versionadded markers and widen enum str annotations
Address review feedback (Ralf):
- Add ``.. versionadded:: 1.1.0`` to the four new texture enums in typing.py
(ArrayFormatType, AddressModeType, FilterModeType, ReadModeType) and to the
texture classes that lacked a class-level marker (ResourceDescriptor,
TextureObject, OpaqueArray, MipmappedArray, SurfaceObject). Remove the
redundant method-level markers now covered at class level.
- Widen the enum-bearing TextureObjectOptions field annotations to include
``str`` (address_mode, filter_mode, read_mode, mipmap_filter_mode), matching
the runtime string coercion this PR adds and existing convention elsewhere in
cuda.core. Note "Plain strings are accepted" on the affected fields.
- Regenerate .pyi stubs.
1 parent ed4e31e commit 8b20f77
21 files changed
Lines changed: 1515 additions & 929 deletions
File tree
- cuda_core
- cuda/core
- texture
- docs/source
- examples
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
909 | 913 | | |
910 | 914 | | |
911 | 915 | | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
912 | 1025 | | |
913 | 1026 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
47 | 57 | | |
48 | 58 | | |
49 | 59 | | |
| |||
1456 | 1466 | | |
1457 | 1467 | | |
1458 | 1468 | | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
1459 | 1596 | | |
1460 | 1597 | | |
1461 | 1598 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
15 | 21 | | |
16 | | - | |
17 | | - | |
| 22 | + | |
| 23 | + | |
18 | 24 | | |
19 | 25 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 26 | | |
24 | | - | |
25 | 27 | | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | | - | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
0 commit comments