Commit f84a7cf
cuda.core: make Device methods use their bound context (#2750)
* cuda.core: make Device methods use their bound context
Run context-sensitive Device operations against the Device's bound context while preserving caller state. Centralize context-aware cleanup and synchronous allocation handling so resource lifetimes remain correct.
* cuda.core: address review of #2750
- Fix _SynchronousMemoryResource to record a deallocation token bound to its
own context, so Buffer teardown enters the right context regardless of what
is current, and works with no context current. Move the class to its own
module and resolve the primary context lazily.
- LegacyPinnedMemoryResource.device_id returns -1 as documented; texture
creation over a pinned buffer works again.
- Device.set_current delegates a foreign-device context to its owning device
instead of raising, so the save/restore idiom round-trips across devices.
- Guard empty context handles once in invoke_in_context(_or_undo); warn when
an undo is skipped because the target context is gone.
- context_synchronize and context_get_stream_priority_range release the GIL
like the other helpers. Rename array/mipmap box accessors to get_box.
- Tests: query the driver (cuStreamGetCtx, cross-context cuEventRecord) instead
of comparing cached metadata; add sync(), set_current round-trip, pinned
texture, and synchronous-resource teardown tests; register device_x2 with
the parallel-test plugin.
- Move the release note to 1.3.0 and describe sync() as acting on the bound
context.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* cuda.core tests: fix driver-call plumbing in the bound-context helper
handle_return() takes the whole result tuple, and cuCtxGetDevice() returns a
CUdevice that never compares equal to an int; both made the cross-context
event-record check raise instead of run (or skip) as intended.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* cuda.core: regenerate stub with stubgen-pyx 0.2.22
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* cuda.core: create stream-ordering events in the recorded stream's context
The uniform empty-context guard added for review item 6 broke
create_event_handle_noctx, which relied on an empty handle meaning "current
context". That helper was itself a #2311-class bug: Stream.wait(stream) and
the foreign-array/tensor import paths created their temporary ordering event
in whatever context was current, and cuEventRecord rejects an event from a
different context than the stream it is recorded on, so cross-device waits
failed unless the right device happened to be current.
Replace it with create_event_handle_for_stream, which resolves the stream's
owning context via cuStreamGetCtx and creates the event there. Callers now
check the returned handle and surface the real creation error. With that,
every creation helper requires a context and no exception remains.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>1 parent f48022a commit f84a7cf
34 files changed
Lines changed: 1511 additions & 480 deletions
File tree
- cuda_core
- cuda/core
- _cpp
- _memory
- texture
- docs/source
- release
- tests
- helpers
- memory_ipc
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
70 | 73 | | |
| 74 | + | |
| 75 | + | |
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
| |||
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| 85 | + | |
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
| |||
246 | 252 | | |
247 | 253 | | |
248 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
249 | 266 | | |
250 | 267 | | |
251 | 268 | | |
| |||
287 | 304 | | |
288 | 305 | | |
289 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
290 | 315 | | |
291 | 316 | | |
292 | 317 | | |
| |||
300 | 325 | | |
301 | 326 | | |
302 | 327 | | |
303 | | - | |
304 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
305 | 333 | | |
306 | 334 | | |
307 | | - | |
| 335 | + | |
308 | 336 | | |
309 | 337 | | |
310 | 338 | | |
| |||
371 | 399 | | |
372 | 400 | | |
373 | 401 | | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
378 | 407 | | |
379 | 408 | | |
380 | 409 | | |
| |||
739 | 768 | | |
740 | 769 | | |
741 | 770 | | |
742 | | - | |
| 771 | + | |
743 | 772 | | |
744 | 773 | | |
745 | 774 | | |
| |||
749 | 778 | | |
750 | 779 | | |
751 | 780 | | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
752 | 784 | | |
753 | 785 | | |
754 | 786 | | |
| |||
758 | 790 | | |
759 | 791 | | |
760 | 792 | | |
761 | | - | |
| 793 | + | |
| 794 | + | |
762 | 795 | | |
763 | 796 | | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
764 | 800 | | |
765 | 801 | | |
766 | 802 | | |
767 | 803 | | |
768 | | - | |
| 804 | + | |
| 805 | + | |
769 | 806 | | |
770 | 807 | | |
771 | | - | |
| 808 | + | |
| 809 | + | |
772 | 810 | | |
773 | 811 | | |
774 | | - | |
| 812 | + | |
| 813 | + | |
775 | 814 | | |
776 | 815 | | |
777 | 816 | | |
778 | 817 | | |
779 | 818 | | |
780 | 819 | | |
781 | | - | |
| 820 | + | |
| 821 | + | |
782 | 822 | | |
783 | 823 | | |
784 | 824 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
583 | 583 | | |
584 | 584 | | |
585 | 585 | | |
586 | | - | |
| 586 | + | |
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
591 | 591 | | |
592 | 592 | | |
593 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
594 | 597 | | |
595 | 598 | | |
596 | 599 | | |
| |||
607 | 610 | | |
608 | 611 | | |
609 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
610 | 619 | | |
611 | 620 | | |
612 | 621 | | |
| |||
615 | 624 | | |
616 | 625 | | |
617 | 626 | | |
618 | | - | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
619 | 630 | | |
620 | 631 | | |
621 | 632 | | |
| |||
647 | 658 | | |
648 | 659 | | |
649 | 660 | | |
650 | | - | |
| 661 | + | |
651 | 662 | | |
652 | 663 | | |
653 | 664 | | |
| |||
659 | 670 | | |
660 | 671 | | |
661 | 672 | | |
662 | | - | |
| 673 | + | |
663 | 674 | | |
664 | 675 | | |
665 | 676 | | |
| |||
675 | 686 | | |
676 | 687 | | |
677 | 688 | | |
678 | | - | |
| 689 | + | |
679 | 690 | | |
680 | 691 | | |
681 | 692 | | |
| |||
718 | 729 | | |
719 | 730 | | |
720 | 731 | | |
721 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
722 | 738 | | |
723 | 739 | | |
724 | 740 | | |
725 | 741 | | |
726 | 742 | | |
727 | 743 | | |
728 | 744 | | |
729 | | - | |
| 745 | + | |
730 | 746 | | |
731 | 747 | | |
732 | 748 | | |
| |||
735 | 751 | | |
736 | 752 | | |
737 | 753 | | |
738 | | - | |
| 754 | + | |
739 | 755 | | |
740 | 756 | | |
741 | | - | |
742 | | - | |
743 | | - | |
| 757 | + | |
744 | 758 | | |
745 | 759 | | |
746 | 760 | | |
| |||
759 | 773 | | |
760 | 774 | | |
761 | 775 | | |
762 | | - | |
| 776 | + | |
763 | 777 | | |
764 | 778 | | |
765 | | - | |
766 | | - | |
767 | | - | |
| 779 | + | |
768 | 780 | | |
769 | 781 | | |
770 | 782 | | |
| |||
783 | 795 | | |
784 | 796 | | |
785 | 797 | | |
786 | | - | |
| 798 | + | |
787 | 799 | | |
788 | 800 | | |
789 | 801 | | |
790 | 802 | | |
791 | 803 | | |
792 | | - | |
793 | | - | |
794 | | - | |
| 804 | + | |
795 | 805 | | |
796 | 806 | | |
797 | 807 | | |
| |||
812 | 822 | | |
813 | 823 | | |
814 | 824 | | |
815 | | - | |
| 825 | + | |
816 | 826 | | |
817 | 827 | | |
818 | 828 | | |
819 | 829 | | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
| 830 | + | |
824 | 831 | | |
825 | 832 | | |
826 | 833 | | |
| |||
0 commit comments