@@ -34,6 +34,7 @@ struct BlockPool {
3434
3535 std::set<Block*, Comparison> blocks;
3636 std::set<Block*, Comparison> unmapped;
37+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
3738 const bool is_small;
3839 PrivatePool* owner_PrivatePool;
3940};
@@ -63,19 +64,14 @@ struct Block {
6364 void * ptr)
6465 : device(device),
6566 queue (queue),
66- stream_uses(),
6767 size(size),
6868 requested_size(0 ),
6969 pool(pool),
7070 ptr(ptr) {}
7171
7272 // constructor for search key
7373 Block (DeviceIndex device, sycl::queue* queue, size_t size)
74- : device(device),
75- queue(queue),
76- stream_uses(),
77- size(size),
78- requested_size(0 ) {}
74+ : device(device), queue(queue), size(size), requested_size(0 ) {}
7975
8076 bool is_split () const {
8177 return (prev != nullptr ) || (next != nullptr );
@@ -142,7 +138,8 @@ struct ExpandableSegment {
142138 // The extra 1/8 allows flexibility for remapping or moving pages within the
143139 // segment when unmapping earlier regions.
144140 constexpr float kVirtualMemOversubscriptFactor = 1 .125f ; // 1 + 1/8
145- max_handles_ = numSegments (device_total * kVirtualMemOversubscriptFactor );
141+ max_handles_ = numSegments (static_cast <size_t >(
142+ static_cast <float >(device_total) * kVirtualMemOversubscriptFactor ));
146143 ptr_ = sycl::ext::oneapi::experimental::reserve_virtual_mem (
147144 segment_size_ * max_handles_, xpu::get_device_context ());
148145 }
@@ -168,15 +165,16 @@ struct ExpandableSegment {
168165 // Allocate and map physical memory for each segment.
169166 for (const auto i : c10::irange (begin, end)) {
170167 TORCH_INTERNAL_ASSERT (!handles_.at (i));
168+ auto & handle = handles_.at (i);
171169 try {
172170 // Allocate physical memory for each segment. Construct the physical_mem
173171 // in-place to avoid copies.
174- handles_. at (i) .emplace (
172+ auto & mem = handle .emplace (
175173 xpu::get_raw_device (device_),
176174 xpu::get_device_context (),
177175 segment_size_);
178176 // Map the allocated physical memory into the virtual address space.
179- handles_. at (i). value () .map (
177+ mem .map (
180178 ptr_ + i * segment_size_,
181179 segment_size_,
182180 sycl::ext::oneapi::experimental::address_access_mode::read_write);
@@ -187,13 +185,14 @@ struct ExpandableSegment {
187185 // Note: constructing physical_mem may over-subscribe device memory but
188186 // not immediately trigger OOM. The actual OOM can occur during map().
189187 // Roll back all segments allocated or mapped in this operation.
190- handles_. at (i) = std:: nullopt ;
188+ handle. reset () ;
191189 for (const auto j : c10::irange (begin, i)) {
192190 sycl::ext::oneapi::experimental::unmap (
191+ // NOLINTNEXTLINE(performance-no-int-to-ptr)
193192 reinterpret_cast <void *>(ptr_ + segment_size_ * j),
194193 segment_size_,
195194 xpu::get_device_context ());
196- handles_.at (j) = std:: nullopt ;
195+ handles_.at (j). reset () ;
197196 }
198197 trimHandles ();
199198 return rangeFromHandles (begin, begin);
@@ -245,6 +244,7 @@ struct ExpandableSegment {
245244 // ranges. Users must explicitly call unmap on all ranges before
246245 // destroying the physical_mem object.
247246 sycl::ext::oneapi::experimental::unmap (
247+ // NOLINTNEXTLINE(performance-no-int-to-ptr)
248248 reinterpret_cast <void *>(ptr_ + segment_size_ * i),
249249 segment_size_,
250250 xpu::get_device_context ());
@@ -318,9 +318,9 @@ struct ExpandableSegment {
318318 size_t max_handles_{0 };
319319 // Physical memory handles for the segments.
320320 std::vector<std::optional<sycl::ext::oneapi::experimental::physical_mem>>
321- handles_{} ;
321+ handles_;
322322 // Peer devices on which this memory could be accessible, reserved.
323- std::vector<c10::DeviceIndex> peers_{} ;
323+ std::vector<c10::DeviceIndex> peers_;
324324};
325325
326326struct AllocParams {
@@ -330,10 +330,7 @@ struct AllocParams {
330330 sycl::queue* queue,
331331 BlockPool* pool,
332332 size_t alloc_size)
333- : search_key(device, queue, size),
334- pool (pool),
335- alloc_size(alloc_size),
336- block(nullptr ) {}
333+ : search_key(device, queue, size), pool(pool), alloc_size(alloc_size) {}
337334
338335 DeviceIndex device () const {
339336 return search_key.device ;
@@ -350,7 +347,7 @@ struct AllocParams {
350347 Block search_key;
351348 BlockPool* pool;
352349 size_t alloc_size;
353- Block* block;
350+ Block* block{ nullptr } ;
354351 StatTypes stat_types = {};
355352};
356353
@@ -987,7 +984,7 @@ class DeviceCachingAllocator {
987984 }
988985
989986 Block* alloc_found_block (
990- AllocParams params,
987+ const AllocParams& params,
991988 size_t orig_size,
992989 bool split_remainder) {
993990 auto size = params.size ();
@@ -1151,7 +1148,7 @@ class DeviceCachingAllocator {
11511148 " Please use `empty_cache` to release all unoccupied cached memory." );
11521149 }
11531150 bool split_remainder = should_split (params.block , params.size ());
1154- return alloc_found_block (std::move ( params) , orig_size, split_remainder);
1151+ return alloc_found_block (params, orig_size, split_remainder);
11551152 }
11561153
11571154 void free (Block* block) {
@@ -1254,7 +1251,8 @@ class DeviceCachingAllocator {
12541251 const auto device_total =
12551252 xpu::get_raw_device (device_index)
12561253 .get_info <sycl::info::device::global_mem_size>();
1257- allowed_memory_maximum = static_cast <size_t >(fraction * device_total);
1254+ allowed_memory_maximum =
1255+ static_cast <size_t >(fraction * static_cast <double >(device_total));
12581256 set_fraction = true ;
12591257 }
12601258
0 commit comments