@@ -121,3 +121,54 @@ TEST(AllocatableCUFTest, StreamDeviceAllocatable) {
121121 cudaDeviceSynchronize ();
122122 EXPECT_EQ (cudaSuccess, cudaGetLastError ());
123123}
124+
125+ TEST (AllocatableAsyncTest, StreamDeviceAllocatable) {
126+ using Fortran::common::TypeCategory;
127+ RTNAME (CUFRegisterAllocator)();
128+ // REAL(4), DEVICE, ALLOCATABLE :: a(:)
129+ auto a{createAllocatable (TypeCategory::Real, 4 )};
130+ a->SetAllocIdx (kDeviceAllocatorPos );
131+ EXPECT_EQ ((int )kDeviceAllocatorPos , a->GetAllocIdx ());
132+ EXPECT_FALSE (a->HasAddendum ());
133+ RTNAME (AllocatableSetBounds)(*a, 0 , 1 , 10 );
134+
135+ cudaStream_t stream;
136+ cudaStreamCreate (&stream);
137+ EXPECT_EQ (cudaSuccess, cudaGetLastError ());
138+
139+ RTNAME (AllocatableAllocate)
140+ (*a, /* asyncObject=*/ (int64_t *)&stream, /* hasStat=*/ false ,
141+ /* errMsg=*/ nullptr , __FILE__, __LINE__);
142+ EXPECT_TRUE (a->IsAllocated ());
143+ cudaDeviceSynchronize ();
144+ EXPECT_EQ (cudaSuccess, cudaGetLastError ());
145+ cudaStream_t s = RTDECL (CUFAssociatedGetStream)(a->raw ().base_addr );
146+ EXPECT_EQ (s, stream);
147+ RTNAME (AllocatableDeallocate)
148+ (*a, /* hasStat=*/ false , /* errMsg=*/ nullptr , __FILE__, __LINE__);
149+ EXPECT_FALSE (a->IsAllocated ());
150+ cudaDeviceSynchronize ();
151+
152+ cudaStream_t defaultStream = 0 ;
153+ RTNAME (AllocatableAllocate)
154+ (*a, /* asyncObject=*/ (int64_t *)&defaultStream, /* hasStat=*/ false ,
155+ /* errMsg=*/ nullptr , __FILE__, __LINE__);
156+ EXPECT_TRUE (a->IsAllocated ());
157+ cudaDeviceSynchronize ();
158+ EXPECT_EQ (cudaSuccess, cudaGetLastError ());
159+ cudaStream_t d = RTDECL (CUFAssociatedGetStream)(a->raw ().base_addr );
160+ EXPECT_EQ (d, defaultStream);
161+ RTNAME (AllocatableDeallocate)
162+ (*a, /* hasStat=*/ false , /* errMsg=*/ nullptr , __FILE__, __LINE__);
163+ EXPECT_FALSE (a->IsAllocated ());
164+ cudaDeviceSynchronize ();
165+
166+ RTNAME (AllocatableAllocate)
167+ (*a, /* asyncObject=*/ nullptr , /* hasStat=*/ false , /* errMsg=*/ nullptr , __FILE__,
168+ __LINE__);
169+ EXPECT_TRUE (a->IsAllocated ());
170+ cudaDeviceSynchronize ();
171+ EXPECT_EQ (cudaSuccess, cudaGetLastError ());
172+ cudaStream_t empty = RTDECL (CUFAssociatedGetStream)(a->raw ().base_addr );
173+ EXPECT_EQ (empty, nullptr );
174+ }
0 commit comments