@@ -462,13 +462,13 @@ end
462462
463463
464464 Metal. encode_wait!(buf2, event, signal_value)
465- Metal . commit!(buf2)
465+ commit!(buf2)
466466
467467 unsafe_copyto!(dev, pointer(a), pointer(B), N, queue= queue1, async= true ) # GPU -> CPU
468468 unsafe_copyto!(dev, pointer(A), pointer(a), N, queue= queue1, async= true ) # CPU -> GPU
469469
470470 Metal. encode_signal!(buf1, event, signal_value)
471- Metal . commit!(buf1)
471+ commit!(buf1)
472472
473473
474474 Metal. wait_completed(buf2)
@@ -489,6 +489,105 @@ end
489489 end
490490end
491491
492+ if Metal. is_macos(v" 15" )
493+ @testset " residency sets" begin
494+
495+ dev = first(devices())
496+
497+ let desc = MTLResidencySetDescriptor()
498+ @test isnothing(desc. label)
499+ desc. label = " Test MTLResidencySetDescriptor"
500+ @test desc. label == " Test MTLResidencySetDescriptor"
501+
502+ @test desc. initialCapacity == 0
503+ desc. initialCapacity = 2
504+ @test desc. initialCapacity == 2
505+ end
506+
507+ desc = MTLResidencySetDescriptor()
508+ desc. initialCapacity = 2
509+ let rset = MTLResidencySet(dev, desc)
510+ alloc1 = MTL. MTLBuffer(dev, 400 )
511+ alloc2 = MTL. MTLBuffer(dev, 1024 )
512+ allocs = [alloc1, alloc2]
513+
514+ # default parameters
515+
516+ @test isnothing(rset. label)
517+ @test rset. device == dev
518+ @test rset. allocationCount == 0
519+ @test rset. allocatedSize == 0
520+ @test isempty(rset. allAllocations)
521+ @test rset. retainCount == 1
522+ @test contains(rset. description, " ResidencySet" )
523+ @test ! MTL. contains_allocation(rset, alloc1)
524+ # @test contains(String(rset.description), "ResidencySet")
525+
526+ # one allocation
527+ MTL. add_allocation!(rset, alloc1)
528+ @test MTL. contains_allocation(rset, alloc1)
529+ @test alloc1 in rset. allAllocations
530+ @test rset. allocationCount == 1
531+ @test rset. allocatedSize == 0 # Updated after it's committed
532+ commit!(rset)
533+ @test rset. allocationCount == 1
534+ @test rset. allocatedSize > 0
535+ MTL. remove_allocation!(rset, alloc1)
536+ @test ! MTL. contains_allocation(rset, alloc1)
537+ @test rset. allocationCount == 1
538+ @test rset. allocatedSize > 0
539+ commit!(rset)
540+ @test rset. allocationCount == 0
541+ @test rset. allocatedSize == 0
542+
543+ # two allocations
544+
545+ MTL. add_allocations!(rset, allocs)
546+ @test MTL. contains_allocation(rset, alloc2)
547+ @test MTL. contains_allocation(rset, alloc2)
548+ @test alloc1 in rset. allAllocations
549+ @test alloc2 in rset. allAllocations
550+ @test rset. allocationCount == 2
551+ @test rset. allocatedSize == 0 # Updated after it's committed
552+ commit!(rset)
553+ @test rset. allocationCount == 2
554+ @test rset. allocatedSize > 0
555+ MTL. remove_allocations!(rset, allocs)
556+ @test ! MTL. contains_allocation(rset, alloc1)
557+ @test ! MTL. contains_allocation(rset, alloc2)
558+ @test rset. allocationCount == 2
559+ @test rset. allocatedSize > 0
560+ commit!(rset)
561+ @test rset. allocationCount == 0
562+ @test rset. allocatedSize == 0
563+
564+ # two allocations but different
565+
566+ MTL. add_allocations!(rset, allocs, 2 )
567+ @test MTL. contains_allocation(rset, alloc2)
568+ @test MTL. contains_allocation(rset, alloc2)
569+ @test alloc1 in rset. allAllocations
570+ @test alloc2 in rset. allAllocations
571+ @test rset. allocationCount == 2
572+ @test rset. allocatedSize == 0 # Updated after it's committed
573+ commit!(rset)
574+ MTL. request_residency!(rset) # ensure no crash
575+ @test rset. allocationCount == 2
576+ @test rset. allocatedSize > 0
577+ MTL. end_residency!(rset) # ensure no crash
578+ MTL. remove_all_allocations!(rset)
579+ @test ! MTL. contains_allocation(rset, alloc1)
580+ @test ! MTL. contains_allocation(rset, alloc2)
581+ @test rset. allocationCount == 2
582+ @test rset. allocatedSize > 0
583+ commit!(rset)
584+ @test rset. allocationCount == 0
585+ @test rset. allocatedSize == 0
586+ end
587+
588+ end # @testset "residency sets" begin
589+ end # if Metal.is_macos(v"15")
590+
492591# TODO : continue adding tests
493592
494593end # @autoreleasepool begin
0 commit comments