Skip to content

Commit b7baf8a

Browse files
authored
[BUILD] Fix arithmetic on a pointer to void warnings. (#549)
1 parent 97db3fc commit b7baf8a

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

tensorflow/core/common_runtime/gpu_tensorpool_allocator.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void GPUTensorPoolAllocator::Init() {
9999
<< max_alignment << ", " << big_bytes_ << ")";
100100
}
101101
if (big_bytes_ > 0) {
102-
big_mem_end_ = big_mem_begin_ + big_bytes_;
102+
big_mem_end_ = static_cast<char*>(big_mem_begin_) + big_bytes_;
103103
} else {
104104
big_mem_end_ = nullptr;
105105
}
@@ -113,7 +113,7 @@ void GPUTensorPoolAllocator::Init() {
113113
auto offset = bin_to_offset[rit->first];
114114
bin = new Bin(bin_info->BlockSize(), bin_info->ChunkSize(),
115115
bin_info->Alignment(), bin_info->VBlocks(),
116-
this, big_mem_begin_ + offset);
116+
this, static_cast<char*>(big_mem_begin_) + offset);
117117
offset_to_bin_[offset] = bin;
118118
} else if (bin_info->VBlocks().size() > 0) {
119119
bin = new Bin(bin_info->BlockSize(), bin_info->ChunkSize(),
@@ -132,7 +132,7 @@ void GPUTensorPoolAllocator::Init() {
132132
auto offset = bin_to_offset[(*it)->BinIndex()];
133133
bin = new Bin((*it)->BlockSize(), (*it)->ChunkSize(),
134134
(*it)->Alignment(), (*it)->VBlocks(),
135-
this, big_mem_begin_ + offset);
135+
this, static_cast<char*>(big_mem_begin_) + offset);
136136
offset_to_bin_[offset] = bin;
137137
} else if ((*it)->VBlocks().size() > 0) {
138138
bin = new Bin((*it)->BlockSize(), (*it)->ChunkSize(),
@@ -162,7 +162,7 @@ void GPUTensorPoolAllocator::Init() {
162162
<< max_alignment << ", " << small_bytes_ << ")";
163163
}
164164
if (small_bytes_ > 0) {
165-
small_mem_end_ = small_mem_begin_ + small_bytes_;
165+
small_mem_end_ = static_cast<char*>(small_mem_begin_) + small_bytes_;
166166
} else {
167167
small_mem_end_ = nullptr;
168168
}
@@ -172,7 +172,7 @@ void GPUTensorPoolAllocator::Init() {
172172
if (b->BlockSize() > 0) {
173173
auto offset = bin_to_offset[b->BinIndex()];
174174
bin = new SmallBin(b->BlockSize(), b->ChunkSize(),
175-
b->Alignment(), small_mem_begin_ + offset);
175+
b->Alignment(), static_cast<char*>(small_mem_begin_) + offset);
176176
offset_to_small_bin_[offset] = bin;
177177
}
178178
small_bins_[b->BinIndex()] = bin;
@@ -285,13 +285,13 @@ GPUTensorPoolAllocator::SmallBin::SmallBin(size_t len,
285285
auto buffer_size = rounded_bytes * len;
286286
begin_ = begin;
287287
if (begin != nullptr) {
288-
end_ = begin + buffer_size;
288+
end_ = static_cast<char*>(begin) + buffer_size;
289289
} else {
290290
end_ = nullptr;
291291
}
292292

293293
for (auto i = 0; i < len; ++i) {
294-
buffer_.emplace(begin + rounded_bytes *i);
294+
buffer_.emplace(static_cast<char*>(begin) + rounded_bytes *i);
295295
}
296296
}
297297

@@ -348,13 +348,13 @@ GPUTensorPoolAllocator::Buffer::Buffer(size_t len, size_t chunk_size,
348348
auto buffer_size = rounded_bytes * len;
349349
begin_ = begin;
350350
if (begin != nullptr) {
351-
end_ = begin + buffer_size;
351+
end_ = static_cast<char*>(begin) + buffer_size;
352352
} else {
353353
end_ = nullptr;
354354
}
355355

356356
for (auto i = 0; i < len; ++i) {
357-
buffer_.emplace(begin + rounded_bytes *i);
357+
buffer_.emplace(static_cast<char*>(begin) + rounded_bytes *i);
358358
}
359359
}
360360

tensorflow/core/common_runtime/tensorpool_allocator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void TensorPoolAllocator::DeallocateRaw(void* ptr) {
168168
auto light_header = GetLightHeader(ptr);
169169
if (light_header != nullptr) {
170170
auto header_size = light_header->header_size;
171-
auto raw_ptr = ptr - header_size;
171+
auto raw_ptr = static_cast<char*>(ptr) - header_size;
172172
// LightHeader not record allocation size
173173
// Free interface ignore the freed num_bytes
174174
sub_allocator_->Free(raw_ptr, 0);
@@ -238,7 +238,7 @@ TensorPoolAllocator::Buffer::Buffer(size_t len, size_t chunk_size,
238238
size_t alignment, SubAllocator* sub_allocator) {
239239
auto rounded_bytes = RoundedBytes(chunk_size, alignment);
240240
auto buffer_size = rounded_bytes * len;
241-
auto p = sub_allocator->Alloc(alignment, buffer_size);
241+
auto p = static_cast<char*>(sub_allocator->Alloc(alignment, buffer_size));
242242
begin_ = p;
243243
end_ = p + buffer_size;
244244

tensorflow/core/framework/embedding/value_ptr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class LightValuePtr : public ValuePtr<V> {
320320
LightValuePtr(Allocator* allocator, size_t size) {
321321
this->ptr_ = (void*)malloc(
322322
sizeof(LightHeader) + sizeof(int64) * size);
323-
memset(this->ptr_ + sizeof(LightHeader), 0, sizeof(int64) * size);
323+
memset(static_cast<char*>(this->ptr_) + sizeof(LightHeader), 0, sizeof(int64) * size);
324324
new ((char*)this->ptr_) LightHeader();
325325
}
326326

@@ -334,7 +334,7 @@ class NormalValuePtr : public ValuePtr<V> {
334334
public:
335335
NormalValuePtr(Allocator* allocator, size_t size) {
336336
this->ptr_ = (void*) malloc(sizeof(NormalHeader) + sizeof(int64) * size);
337-
memset(this->ptr_ + sizeof(NormalHeader), 0, sizeof(int64) * size);
337+
memset(static_cast<char*>(this->ptr_) + sizeof(NormalHeader), 0, sizeof(int64) * size);
338338
new ((char*)this->ptr_) NormalHeader();
339339
}
340340

@@ -379,7 +379,7 @@ class NormalContiguousValuePtr : public ValuePtr<V>{
379379
NormalContiguousValuePtr(Allocator* allocator, size_t size) {
380380
this->ptr_ = allocator->AllocateRaw(Allocator::kAllocatorAlignment,
381381
sizeof(FixedLengthHeader) + sizeof(V) * size);
382-
memset(this->ptr_ + sizeof(FixedLengthHeader), 0, sizeof(V) * size);
382+
memset(static_cast<char*>(this->ptr_) + sizeof(FixedLengthHeader), 0, sizeof(V) * size);
383383
new ((char*)this->ptr_) FixedLengthHeader();
384384
}
385385

0 commit comments

Comments
 (0)