diff options
author | Eugene Zhulenev <ezhulenev@google.com> | 2018-06-08 12:46:39 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-06-08 12:49:36 -0700 |
commit | 7bb79ee219d4efbd92d1ef4e0dbe45f4aee26654 (patch) | |
tree | c03fb870409e717f6d43f8f4128fd45290e13fe1 /tensorflow/python/lib | |
parent | 5b540fe049fbb675eb1b5ea7d03fb4cb96a642c4 (diff) |
Ask NumPy for read only array when converting it to Tensor.
Fix for: #17315
If numpy array is read-only, calling PyArray_FromAny with NPY_ARRAY_CARRAY
flags introduce extra memory copy.
Before:
feed_cpu_variable_read_only: 5.6 GB/sec, min: 17.99, median: 19.54, mean: 19.76
After:
feed_cpu_variable_read_only: 13.2 GB/sec, min: 7.60, median: 7.78, mean: 8.13
PiperOrigin-RevId: 199835695
Diffstat (limited to 'tensorflow/python/lib')
-rw-r--r-- | tensorflow/python/lib/core/ndarray_tensor.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tensorflow/python/lib/core/ndarray_tensor.cc b/tensorflow/python/lib/core/ndarray_tensor.cc index 2acab92764..ec1ba7b8f7 100644 --- a/tensorflow/python/lib/core/ndarray_tensor.cc +++ b/tensorflow/python/lib/core/ndarray_tensor.cc @@ -411,7 +411,7 @@ Status PyArrayToTF_Tensor(PyObject* ndarray, Safe_TF_TensorPtr* out_tensor) { // Make sure we dereference this array object in case of error, etc. Safe_PyObjectPtr array_safe(make_safe( - PyArray_FromAny(ndarray, nullptr, 0, 0, NPY_ARRAY_CARRAY, nullptr))); + PyArray_FromAny(ndarray, nullptr, 0, 0, NPY_ARRAY_CARRAY_RO, nullptr))); if (!array_safe) return errors::InvalidArgument("Not a ndarray."); PyArrayObject* array = reinterpret_cast<PyArrayObject*>(array_safe.get()); |