@@ -21,8 +21,8 @@ limitations under the License.
2121#include < algorithm>
2222#include < vector>
2323
24+ #include " tensorflow/core/common_runtime/device/device_id_utils.h"
2425#include " tensorflow/core/common_runtime/gpu/gpu_id.h"
25- #include " tensorflow/core/common_runtime/gpu/gpu_id_utils.h"
2626#include " tensorflow/core/common_runtime/gpu/gpu_init.h"
2727#include " tensorflow/core/framework/typed_allocator.h"
2828#include " tensorflow/core/lib/core/threadpool.h"
@@ -52,11 +52,18 @@ static void CheckStats(Allocator* a, int64 num_allocs, int64 bytes_in_use,
5252 EXPECT_EQ (stats->largest_alloc_size , largest_alloc_size);
5353}
5454
55+ se::StreamExecutor* ExecutorForPlatformGpuId (
56+ PlatformDeviceId platform_device_id) {
57+ return DeviceIdUtil::ExecutorForPlatformDeviceId (GPUMachineManager (),
58+ platform_device_id)
59+ .ValueOrDie ();
60+ }
61+
5562TEST (GPUBFCAllocatorTest, NoDups) {
5663 PlatformGpuId platform_gpu_id (0 );
5764 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
58- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
59- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
65+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
66+ false /* use_unified_memory*/ , {}, {});
6067 GPUBFCAllocator a (sub_allocator, 1 << 30 , " GPU_0_bfc" );
6168 CheckStats (&a, 0 , 0 , 0 , 0 );
6269
@@ -88,8 +95,8 @@ TEST(GPUBFCAllocatorTest, NoDups) {
8895TEST (GPUBFCAllocatorTest, AllocationsAndDeallocations) {
8996 PlatformGpuId platform_gpu_id (0 );
9097 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
91- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
92- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
98+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
99+ false /* use_unified_memory*/ , {}, {});
93100 GPUBFCAllocator a (sub_allocator, 1 << 30 , " GPU_0_bfc" );
94101 // Allocate 256 raw pointers of sizes between 100 bytes and about
95102 // a meg
@@ -150,8 +157,8 @@ TEST(GPUBFCAllocatorTest, AllocationsAndDeallocations) {
150157TEST (GPUBFCAllocatorTest, ExerciseCoalescing) {
151158 PlatformGpuId platform_gpu_id (0 );
152159 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
153- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
154- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
160+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
161+ false /* use_unified_memory*/ , {}, {});
155162 GPUBFCAllocator a (sub_allocator, 1 << 30 , " GPU_0_bfc" );
156163 CheckStats (&a, 0 , 0 , 0 , 0 );
157164
@@ -189,8 +196,8 @@ TEST(GPUBFCAllocatorTest, ExerciseCoalescing) {
189196TEST (GPUBFCAllocatorTest, AllocateZeroBufSize) {
190197 PlatformGpuId platform_gpu_id (0 );
191198 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
192- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
193- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
199+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
200+ false /* use_unified_memory*/ , {}, {});
194201 GPUBFCAllocator a (sub_allocator, 1 << 30 , " GPU_0_bfc" );
195202 float * ptr = TypedAllocator::Allocate<float >(&a, 0 , {});
196203 EXPECT_EQ (nullptr , ptr);
@@ -199,17 +206,17 @@ TEST(GPUBFCAllocatorTest, AllocateZeroBufSize) {
199206TEST (GPUBFCAllocatorTest, TracksSizes) {
200207 PlatformGpuId platform_gpu_id (0 );
201208 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
202- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
203- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
209+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
210+ false /* use_unified_memory*/ , {}, {});
204211 GPUBFCAllocator a (sub_allocator, 1 << 30 , " GPU_0_bfc" );
205212 EXPECT_EQ (true , a.TracksAllocationSizes ());
206213}
207214
208215TEST (GPUBFCAllocatorTest, AllocatedVsRequested) {
209216 PlatformGpuId platform_gpu_id (0 );
210217 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
211- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
212- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
218+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
219+ false /* use_unified_memory*/ , {}, {});
213220 GPUBFCAllocator a (sub_allocator, 1 << 30 , " GPU_0_bfc" );
214221 float * t1 = TypedAllocator::Allocate<float >(&a, 1 , {});
215222 EXPECT_EQ (4 , a.RequestedSize (t1));
@@ -220,8 +227,8 @@ TEST(GPUBFCAllocatorTest, AllocatedVsRequested) {
220227TEST (GPUBFCAllocatorTest, TestCustomMemoryLimit) {
221228 PlatformGpuId platform_gpu_id (0 );
222229 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
223- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
224- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
230+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
231+ false /* use_unified_memory*/ , {}, {});
225232 // Configure a 1MiB byte limit
226233 GPUBFCAllocator a (sub_allocator, 1 << 20 , " GPU_0_bfc" );
227234
@@ -240,8 +247,8 @@ TEST(GPUBFCAllocatorTest, AllocationsAndDeallocationsWithGrowth) {
240247 // Max of 2GiB, but starts out small.
241248 PlatformGpuId platform_gpu_id (0 );
242249 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
243- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
244- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
250+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
251+ false /* use_unified_memory*/ , {}, {});
245252 GPUBFCAllocator a (sub_allocator, 1LL << 31 , " GPU_0_bfc" );
246253
247254 // Allocate 10 raw pointers of sizes between 100 bytes and about
@@ -306,12 +313,12 @@ TEST(GPUBFCAllocatorTest, AllocationsAndDeallocationsWithGrowth) {
306313TEST (GPUBFCAllocatorTest, DISABLED_AllocatorReceivesZeroMemory) {
307314 PlatformGpuId platform_gpu_id (0 );
308315 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
309- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
310- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
316+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
317+ false /* use_unified_memory*/ , {}, {});
311318 GPUBFCAllocator a (sub_allocator, 1UL << 60 , " GPU_0_bfc" );
312- sub_allocator = new GPUMemAllocator (
313- GpuIdUtil::ExecutorForPlatformGpuId ( platform_gpu_id). ValueOrDie () ,
314- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
319+ sub_allocator = new GPUMemAllocator (ExecutorForPlatformGpuId (platform_gpu_id),
320+ platform_gpu_id,
321+ false /* use_unified_memory*/ , {}, {});
315322 GPUBFCAllocator b (sub_allocator, 1UL << 60 , " GPU_0_bfc" );
316323 void * amem = a.AllocateRaw (1 , 1 );
317324 void * bmem = b.AllocateRaw (1 , 1 << 30 );
@@ -322,8 +329,8 @@ TEST(GPUBFCAllocatorTest, DISABLED_AllocatorReceivesZeroMemory) {
322329static void BM_Allocation (int iters) {
323330 PlatformGpuId platform_gpu_id (0 );
324331 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
325- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
326- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
332+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
333+ false /* use_unified_memory*/ , {}, {});
327334 GPUBFCAllocator a (sub_allocator, 1uLL << 33 , " GPU_0_bfc" );
328335 // Exercise a few different allocation sizes
329336 std::vector<size_t > sizes = {256 , 4096 , 16384 , 524288 ,
@@ -342,8 +349,8 @@ BENCHMARK(BM_Allocation);
342349static void BM_AllocationThreaded (int iters, int num_threads) {
343350 PlatformGpuId platform_gpu_id (0 );
344351 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
345- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
346- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
352+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
353+ false /* use_unified_memory*/ , {}, {});
347354 GPUBFCAllocator a (sub_allocator, 1uLL << 33 , " GPU_0_bfc" );
348355 thread::ThreadPool pool (Env::Default (), " test" , num_threads);
349356 std::atomic_int_fast32_t count (iters);
@@ -382,8 +389,8 @@ BENCHMARK(BM_AllocationThreaded)->Arg(1)->Arg(4)->Arg(16);
382389static void BM_AllocationDelayed (int iters, int delay) {
383390 PlatformGpuId platform_gpu_id (0 );
384391 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
385- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
386- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
392+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
393+ false /* use_unified_memory*/ , {}, {});
387394 GPUBFCAllocator a (sub_allocator, 1 << 30 , " GPU_0_bfc" );
388395 // Exercise a few different allocation sizes
389396 std::vector<int > sizes = {256 , 4096 , 16384 , 4096 , 512 , 1024 , 1024 };
@@ -426,8 +433,8 @@ class GPUBFCAllocatorPrivateMethodsTest : public ::testing::Test {
426433 void TestBinDebugInfo () {
427434 PlatformGpuId platform_gpu_id (0 );
428435 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
429- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
430- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
436+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
437+ false /* use_unified_memory*/ , {}, {});
431438 GPUBFCAllocator a (sub_allocator, 1 << 30 , " GPU_0_bfc" );
432439
433440 std::vector<void *> initial_ptrs;
@@ -526,8 +533,8 @@ class GPUBFCAllocatorPrivateMethodsTest : public ::testing::Test {
526533 void TestLog2FloorNonZeroSlow () {
527534 PlatformGpuId platform_gpu_id (0 );
528535 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
529- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
530- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
536+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
537+ false /* use_unified_memory*/ , {}, {});
531538 GPUBFCAllocator a (sub_allocator, 1 /* total_memory */ , " GPU_0_bfc" );
532539 EXPECT_EQ (-1 , a.Log2FloorNonZeroSlow (0 ));
533540 EXPECT_EQ (0 , a.Log2FloorNonZeroSlow (1 ));
@@ -545,8 +552,8 @@ class GPUBFCAllocatorPrivateMethodsTest : public ::testing::Test {
545552 unsetenv (" TF_FORCE_GPU_ALLOW_GROWTH" );
546553 options.set_allow_growth (true );
547554 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
548- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
549- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
555+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
556+ false /* use_unified_memory*/ , {}, {});
550557 GPUBFCAllocator unset_flag_allocator (sub_allocator, 1LL << 31 , options,
551558 " GPU_0_bfc" );
552559 EXPECT_EQ (GPUBFCAllocator::RoundedBytes (size_t {1048576 }),
@@ -556,8 +563,8 @@ class GPUBFCAllocatorPrivateMethodsTest : public ::testing::Test {
556563 setenv (" TF_FORCE_GPU_ALLOW_GROWTH" , " unparseable" , 1 );
557564 options.set_allow_growth (true );
558565 sub_allocator = new GPUMemAllocator (
559- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
560- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
566+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
567+ false /* use_unified_memory*/ , {}, {});
561568 GPUBFCAllocator unparsable_flag_allocator (sub_allocator, 1LL << 31 , options,
562569 " GPU_1_bfc" );
563570 EXPECT_EQ (GPUBFCAllocator::RoundedBytes (size_t {1048576 }),
@@ -568,8 +575,8 @@ class GPUBFCAllocatorPrivateMethodsTest : public ::testing::Test {
568575 setenv (" TF_FORCE_GPU_ALLOW_GROWTH" , " true" , 1 );
569576 options.set_allow_growth (false );
570577 sub_allocator = new GPUMemAllocator (
571- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
572- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
578+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
579+ false /* use_unified_memory*/ , {}, {});
573580 GPUBFCAllocator force_allow_growth_allocator (sub_allocator, 1LL << 31 ,
574581 options, " GPU_2_bfc" );
575582 EXPECT_EQ (GPUBFCAllocator::RoundedBytes (size_t {1048576 }),
@@ -580,8 +587,8 @@ class GPUBFCAllocatorPrivateMethodsTest : public ::testing::Test {
580587 setenv (" TF_FORCE_GPU_ALLOW_GROWTH" , " false" , 1 );
581588 options.set_allow_growth (true );
582589 sub_allocator = new GPUMemAllocator (
583- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
584- platform_gpu_id, false /* use_unified_memory*/ , {}, {});
590+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
591+ false /* use_unified_memory*/ , {}, {});
585592 GPUBFCAllocator force_no_allow_growth_allocator (sub_allocator, 1LL << 31 ,
586593 options, " GPU_3_bfc" );
587594 EXPECT_EQ (GPUBFCAllocator::RoundedBytes (1LL << 31 ),
@@ -595,8 +602,8 @@ class GPUBFCAllocatorPrivateMethodsTest : public ::testing::Test {
595602 // Max of 2GiB, but starts out small.
596603 PlatformGpuId platform_gpu_id (0 );
597604 GPUMemAllocator* sub_allocator = new GPUMemAllocator (
598- GpuIdUtil:: ExecutorForPlatformGpuId (platform_gpu_id). ValueOrDie () ,
599- platform_gpu_id, /* use_unified_memory=*/ false , {}, {});
605+ ExecutorForPlatformGpuId (platform_gpu_id), platform_gpu_id ,
606+ /* use_unified_memory=*/ false , {}, {});
600607 GPUBFCAllocator a (sub_allocator, 1LL << 31 , options, " GPU_0_bfc" );
601608
602609 // Allocate 128 raw pointers of 4 megs.
0 commit comments