Change 64-bit integers to pointer-sized ints at a few places.

PiperOrigin-RevId: 276358885
Change-Id: I0d240c73af8fde2a8bb2a963a83eb997995a1436
This commit is contained in:
Robert David 2019-10-23 15:02:41 -07:00 committed by TensorFlower Gardener
parent d2fac81efc
commit 7a2e4a4f68
4 changed files with 15 additions and 9 deletions

View File

@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "tensorflow/lite/arena_planner.h" #include "tensorflow/lite/arena_planner.h"
#include <cstdint>
#include <utility> #include <utility>
namespace tflite { namespace tflite {
@ -40,7 +42,7 @@ ArenaPlanner::ArenaPlanner(TfLiteContext* context,
ArenaPlanner::~ArenaPlanner() {} ArenaPlanner::~ArenaPlanner() {}
int64_t ArenaPlanner::BasePointer(TfLiteAllocationType type) { std::intptr_t ArenaPlanner::BasePointer(TfLiteAllocationType type) {
if (type == kTfLiteArenaRwPersistent) { if (type == kTfLiteArenaRwPersistent) {
return persistent_arena_.BasePointer(); return persistent_arena_.BasePointer();
} }

View File

@ -15,6 +15,7 @@ limitations under the License.
#ifndef TENSORFLOW_LITE_ARENA_PLANNER_H_ #ifndef TENSORFLOW_LITE_ARENA_PLANNER_H_
#define TENSORFLOW_LITE_ARENA_PLANNER_H_ #define TENSORFLOW_LITE_ARENA_PLANNER_H_
#include <cstdint>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -67,7 +68,7 @@ class ArenaPlanner : public MemoryPlanner {
TfLiteStatus ExecuteAllocations(int first_node, int last_node) override; TfLiteStatus ExecuteAllocations(int first_node, int last_node) override;
// Returns the base arena location for a given allocation type. // Returns the base arena location for a given allocation type.
int64_t BasePointer(TfLiteAllocationType type); std::intptr_t BasePointer(TfLiteAllocationType type);
private: private:
// Make sure all the arenas have reserved enough memory to store all their // Make sure all the arenas have reserved enough memory to store all their

View File

@ -15,11 +15,12 @@ limitations under the License.
#include "tensorflow/lite/arena_planner.h" #include "tensorflow/lite/arena_planner.h"
#include <cstdarg> #include <cstdarg>
#include <cstdint>
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "tensorflow/lite/testing/util.h"
#include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/logging.h"
#include "tensorflow/lite/testing/util.h"
namespace tflite { namespace tflite {
namespace { namespace {
@ -183,16 +184,16 @@ class ArenaPlannerTest : public ::testing::Test {
// Returns the actual offset of a given tensor, relative to the start of its // Returns the actual offset of a given tensor, relative to the start of its
// arena. // arena.
int64_t GetOffset(int tensor_index) { std::ptrdiff_t GetOffset(int tensor_index) {
const TfLiteTensor& tensor = (*graph_->tensors())[tensor_index]; const TfLiteTensor& tensor = (*graph_->tensors())[tensor_index];
return reinterpret_cast<int64_t>(tensor.data.raw) - return reinterpret_cast<std::intptr_t>(tensor.data.raw) -
planner_->BasePointer(tensor.allocation_type); planner_->BasePointer(tensor.allocation_type);
} }
// Returns the first aligned offset after a given tensor. // Returns the first aligned offset after a given tensor.
int64_t GetOffsetAfter(int tensor_index) { std::ptrdiff_t GetOffsetAfter(int tensor_index) {
const TfLiteTensor& tensor = (*graph_->tensors())[tensor_index]; const TfLiteTensor& tensor = (*graph_->tensors())[tensor_index];
int64_t offset = GetOffset(tensor_index) + tensor.bytes; std::ptrdiff_t offset = GetOffset(tensor_index) + tensor.bytes;
// We must make sure the offset is aligned to kDefaultArenaAlignment. // We must make sure the offset is aligned to kDefaultArenaAlignment.
if (offset % kTensorAlignment != 0) { if (offset % kTensorAlignment != 0) {
offset += kTensorAlignment - offset % kTensorAlignment; offset += kTensorAlignment - offset % kTensorAlignment;

View File

@ -15,8 +15,10 @@ limitations under the License.
#ifndef TENSORFLOW_LITE_SIMPLE_MEMORY_ARENA_H_ #ifndef TENSORFLOW_LITE_SIMPLE_MEMORY_ARENA_H_
#define TENSORFLOW_LITE_SIMPLE_MEMORY_ARENA_H_ #define TENSORFLOW_LITE_SIMPLE_MEMORY_ARENA_H_
#include <cstdint>
#include <list> #include <list>
#include <memory> #include <memory>
#include "tensorflow/lite/c/c_api_internal.h" #include "tensorflow/lite/c/c_api_internal.h"
namespace tflite { namespace tflite {
@ -69,8 +71,8 @@ class SimpleMemoryArena {
TfLiteStatus Clear(); TfLiteStatus Clear();
int64_t BasePointer() const { std::intptr_t BasePointer() const {
return reinterpret_cast<int64_t>(underlying_buffer_aligned_ptr_); return reinterpret_cast<std::intptr_t>(underlying_buffer_aligned_ptr_);
} }
private: private: