diff options
author | Kenneth Heafield <kpu@users.noreply.github.com> | 2021-04-14 18:48:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-14 18:48:51 +0300 |
commit | bb6092da2b89c3882aa256480cef13081fd6f50f (patch) | |
tree | b01e44c14ab34077eb1af08195c78629028db603 /src | |
parent | 8a53b761d5bc922e4ab058a4487ad362d2edefaf (diff) |
Compute tensor size using integers (#851)
Diffstat (limited to 'src')
-rw-r--r-- | src/tensors/allocator.h | 5 | ||||
-rw-r--r-- | src/tensors/device.h | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/tensors/allocator.h b/src/tensors/allocator.h index 9dc44f58..1844be14 100644 --- a/src/tensors/allocator.h +++ b/src/tensors/allocator.h @@ -175,8 +175,9 @@ public: reserve(bytes); } - size_t alignedSize(size_t size) { - return (size_t)(ceil(size / (double)alignment_) * alignment_); + size_t alignedSize(size_t size) const { + size_t over = size + alignment_ - 1; + return over - (over % alignment_); } void throwAtReallocation(bool throwRealloc) { throw_ = throwRealloc; } diff --git a/src/tensors/device.h b/src/tensors/device.h index 0be6c076..5fe3c1fb 100644 --- a/src/tensors/device.h +++ b/src/tensors/device.h @@ -15,8 +15,9 @@ protected: size_t size_{0}; size_t alignment_; - size_t align(size_t size) { - return (size_t)(ceil(size / (float)alignment_) * alignment_); + size_t align(size_t size) const { + size_t over = size + alignment_ - 1; + return over - (over % alignment_); } public: |