summaryrefslogtreecommitdiff
path: root/aten
diff options
context:
space:
mode:
authorPeter Goldsborough <peter@goldsborough.me>2018-04-28 01:51:16 +0100
committerGitHub <noreply@github.com>2018-04-28 01:51:16 +0100
commit7b09bc72a55aba4614194ea2acd77bddd6490e70 (patch)
treeb38c02147e15caab75904592279e7e053fc8902e /aten
parent733e2967b11db3e89e51e7145963c96d3050b1ee (diff)
downloadpytorch-7b09bc72a55aba4614194ea2acd77bddd6490e70.tar.gz
pytorch-7b09bc72a55aba4614194ea2acd77bddd6490e70.tar.bz2
pytorch-7b09bc72a55aba4614194ea2acd77bddd6490e70.zip
[WIP] Enable WERROR in tests (#6539)
* Enable WERROR in tests * Also set WERROR=1 for cpp_build in CI * Enable Werror after the compiler checks * Remove -DWERROR because its picked up from the env var * Had to fix some errors in aten/contrib/data * Allow an uninitialized variable in ReduceOpsKernel.cpp * Use CUDNN_DATA_UINT8 in cuDNN type string conversion * Fixes and use target_compile_options * Fix uninitialized variables in THNN * Include Python.h earlier in tensor_types.cpp * Use CUDNN_VERSION 7100 instead of 7000? * More Python.h includes * Make switch case in common_subexpression_elimination.cpp exhaustive * Build with WERROR=0 just to see all the warnings * Remove some Python includes * Enable WERROR=1 again * Bring back switch case default
Diffstat (limited to 'aten')
-rw-r--r--aten/CMakeLists.txt10
-rw-r--r--aten/contrib/data/BatchDataset.cc4
-rw-r--r--aten/contrib/data/ResampleDataset.cc4
-rw-r--r--aten/contrib/data/ShuffleDataset.cc2
-rw-r--r--aten/contrib/meter/APMeter.cc4
-rw-r--r--aten/contrib/meter/AUCMeter.cc2
-rw-r--r--aten/contrib/meter/ClassErrorMeter.cc6
-rw-r--r--aten/contrib/meter/MSEMeter.cc2
-rw-r--r--aten/src/ATen/CMakeLists.txt16
-rw-r--r--aten/src/ATen/PinnedMemoryAllocator.cpp6
-rw-r--r--aten/src/ATen/cudnn/Descriptors.cpp11
-rw-r--r--aten/src/ATen/native/Normalization.cpp4
-rw-r--r--aten/src/ATen/native/cpu/ReduceOpsKernel.cpp1
-rw-r--r--aten/src/TH/THDiskFile.c66
-rw-r--r--aten/src/TH/THFilePrivate.h42
-rw-r--r--aten/src/TH/THGeneral.c13
-rw-r--r--aten/src/TH/THMemoryFile.c86
-rw-r--r--aten/src/THNN/generic/SpatialAdaptiveAveragePooling.c18
-rw-r--r--aten/src/THNN/generic/SpatialAdaptiveMaxPooling.c24
-rw-r--r--aten/src/THNN/generic/VolumetricAdaptiveAveragePooling.c26
-rw-r--r--aten/src/THNN/generic/VolumetricAdaptiveMaxPooling.c28
21 files changed, 196 insertions, 179 deletions
diff --git a/aten/CMakeLists.txt b/aten/CMakeLists.txt
index 677dce9068..e37db92cc2 100644
--- a/aten/CMakeLists.txt
+++ b/aten/CMakeLists.txt
@@ -28,13 +28,9 @@ if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif()
-IF(NOT MSVC)
- set(CMAKE_CXX_FLAGS "--std=c++11 -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-unused-parameter -Wno-unknown-pragmas -Wno-vla -fexceptions ${CMAKE_CXX_FLAGS}")
- set(CMAKE_C_FLAGS "-fexceptions ${CMAKE_C_FLAGS}")
- if ($ENV{WERROR})
- set(CMAKE_CXX_FLAGS "-Werror ${CMAKE_CXX_FLAGS}")
- endif()
-ENDIF(NOT MSVC)
+if(NOT MSVC)
+ set(CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}")
+endif()
INCLUDE(CheckCXXSourceCompiles)
diff --git a/aten/contrib/data/BatchDataset.cc b/aten/contrib/data/BatchDataset.cc
index 77250a5680..e4d4ae4580 100644
--- a/aten/contrib/data/BatchDataset.cc
+++ b/aten/contrib/data/BatchDataset.cc
@@ -27,7 +27,7 @@ void BatchDataset::getField(uint64_t idx, std::string& fieldkey, at::Tensor& fie
// loop over samples:
Tensor singlefield, buffer;
uint64_t maxsize = std::min(batchsize_, size_ - idx * batchsize_);
- for(int n = 0; n < maxsize; n++) {
+ for(uint64_t n = 0; n < maxsize; n++) {
// get sample:
uint64_t batchidx = idx * batchsize_ + n;
@@ -39,7 +39,7 @@ void BatchDataset::getField(uint64_t idx, std::string& fieldkey, at::Tensor& fie
// determine size of batch:
std::vector<int64_t> fieldsize;
fieldsize.push_back(maxsize);
- for(uint64_t d = 0; d < singlefield.dim(); ++d) {
+ for(long d = 0; d < singlefield.dim(); ++d) {
fieldsize.push_back(singlefield.size(d));
}
diff --git a/aten/contrib/data/ResampleDataset.cc b/aten/contrib/data/ResampleDataset.cc
index f5d6cce418..ce8d3547dd 100644
--- a/aten/contrib/data/ResampleDataset.cc
+++ b/aten/contrib/data/ResampleDataset.cc
@@ -10,7 +10,7 @@ ResampleDataset::ResampleDataset(Dataset& dataset) {
size_ = dataset.size();
perm_ = std::vector<uint64_t>();
perm_.reserve(size_);
- for(int n = 0; n < size_; ++n)
+ for(uint64_t n = 0; n < size_; ++n)
perm_[n] = n;
}
@@ -37,7 +37,7 @@ void ResampleDataset::getField(uint64_t idx, std::string& fieldkey, at::Tensor&
void ResampleDataset::resample() {
if(permfunc_) {
perm_.reserve(size_);
- for(int n = 0; n < size_; ++n)
+ for(uint64_t n = 0; n < size_; ++n)
perm_[n] = permfunc_(n);
}
}
diff --git a/aten/contrib/data/ShuffleDataset.cc b/aten/contrib/data/ShuffleDataset.cc
index f9ce91242c..25ebb38c69 100644
--- a/aten/contrib/data/ShuffleDataset.cc
+++ b/aten/contrib/data/ShuffleDataset.cc
@@ -10,7 +10,7 @@ ShuffleDataset::ShuffleDataset(Dataset& dataset) : ResampleDataset(dataset) {
void ShuffleDataset::resample() {
perm_.reserve(size_);
- for(int n = 0; n < size_; ++n)
+ for(size_t n = 0; n < size_; ++n)
perm_[n] = n;
std::random_shuffle(perm_.begin(), perm_.end());
}
diff --git a/aten/contrib/meter/APMeter.cc b/aten/contrib/meter/APMeter.cc
index 42ff915c11..316d436646 100644
--- a/aten/contrib/meter/APMeter.cc
+++ b/aten/contrib/meter/APMeter.cc
@@ -63,7 +63,7 @@ void APMeter::value(Tensor& val) {
Tensor range = val.type().range(0,curoutputs.size(0));
// loop over all classes:
- for(uint64_t k = 0; k < curoutputs.size(1); ++k) {
+ for(long k = 0; k < curoutputs.size(1); ++k) {
// sort scores:
outputbuffer = curoutputs.narrow( 1, k, 1);
@@ -78,7 +78,7 @@ void APMeter::value(Tensor& val) {
double * precision_d = precision.data<double>();
// compute average precision:
val_d[k] = .0;
- for(uint64_t n = 0; n < precision.size(0); ++n) {
+ for(long n = 0; n < precision.size(0); ++n) {
if(targetbuffer_d[n] != 0.)
val_d[k] += precision_d[n];
}
diff --git a/aten/contrib/meter/AUCMeter.cc b/aten/contrib/meter/AUCMeter.cc
index d36587d4ea..fdd352b701 100644
--- a/aten/contrib/meter/AUCMeter.cc
+++ b/aten/contrib/meter/AUCMeter.cc
@@ -34,7 +34,7 @@ void AUCMeter::value(Tensor& val) {
double * tpr_d = tpr.data<double>();
double * fpr_d = fpr.data<double>();
- for(uint64_t n = 1; n <= numel(outputs); ++n) {
+ for(long n = 1; n <= numel(outputs); ++n) {
if(targets_d[sortidx_d[n - 1]] == 1) {
tpr_d[n] = tpr_d[n - 1] + 1.;
fpr_d[n] = fpr_d[n - 1];
diff --git a/aten/contrib/meter/ClassErrorMeter.cc b/aten/contrib/meter/ClassErrorMeter.cc
index bedfd22462..a24e850542 100644
--- a/aten/contrib/meter/ClassErrorMeter.cc
+++ b/aten/contrib/meter/ClassErrorMeter.cc
@@ -33,11 +33,11 @@ void ClassErrorMeter::add(Tensor& output, Tensor& target) {
// update counts:
Tensor val, idx;
std::tie(val, idx) = topk(output, numel(topkval_), 1, true, true);
- for(uint64_t n = 0; n < output.size(0); ++n) {
+ for(long n = 0; n < output.size(0); ++n) {
bool targetseen = false;
Tensor idx_n = idx.select(0,n);
auto idx_n_d = idx_n.data<int64_t>();
- for(uint64_t k = 0; k < numel(topkval_); ++k) {
+ for(long k = 0; k < numel(topkval_); ++k) {
n_++;
if(targetseen) {
sumval_d[k]++;
@@ -53,7 +53,7 @@ void ClassErrorMeter::value(Tensor& val) {
val.resize_({numel(topkval_)});
auto val_d = val.data<double>();
auto sumval_d = sumval_.data<int16_t>();
- for(uint64_t k = 0; k < numel(topkval_); ++k) {
+ for(long k = 0; k < numel(topkval_); ++k) {
val_d[k] = 1.0 - (double(sumval_d[k]) / double(n_));
}
}
diff --git a/aten/contrib/meter/MSEMeter.cc b/aten/contrib/meter/MSEMeter.cc
index 012b6b8b0c..431415b08a 100644
--- a/aten/contrib/meter/MSEMeter.cc
+++ b/aten/contrib/meter/MSEMeter.cc
@@ -18,7 +18,7 @@ void MSEMeter::add(Tensor& output, Tensor& target) {
Tensor t = output.sub(target);
Tensor result = t.mul(t).contiguous().toType(CPU(kDouble));
double * data = result.data<double>();
- for(uint64_t n = 0; n < numel(result); ++n) {
+ for(long n = 0; n < numel(result); ++n) {
n_++;
val_ += ( (1. / ((double)n_ - 1.) * val_) +
((1. / (double)n_) * data[n]));
diff --git a/aten/src/ATen/CMakeLists.txt b/aten/src/ATen/CMakeLists.txt
index a12378a081..13670aa73e 100644
--- a/aten/src/ATen/CMakeLists.txt
+++ b/aten/src/ATen/CMakeLists.txt
@@ -237,6 +237,22 @@ ELSE()
ENDIF()
ADD_DEPENDENCIES(ATen aten_files_are_generated)
+if(NOT MSVC)
+ target_compile_options(ATen
+ PRIVATE
+ -Wall
+ -Wextra
+ -fexceptions
+ -Wno-missing-field-initializers
+ -Wno-type-limits
+ -Wno-unused-parameter
+ -Wno-unknown-pragmas)
+
+ if ($ENV{WERROR})
+ target_compile_options(ATen PRIVATE -Werror)
+ endif()
+endif()
+
set(TBB_ROOT_DIR "${PROJECT_SOURCE_DIR}/../third_party/tbb")
set(TBB_BUILD_STATIC ON CACHE BOOL " " FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL " " FORCE)
diff --git a/aten/src/ATen/PinnedMemoryAllocator.cpp b/aten/src/ATen/PinnedMemoryAllocator.cpp
index 8a417546a4..ae750fcfdd 100644
--- a/aten/src/ATen/PinnedMemoryAllocator.cpp
+++ b/aten/src/ATen/PinnedMemoryAllocator.cpp
@@ -16,7 +16,9 @@ void* PinnedMemoryAllocator::allocate(std::size_t n) const {
#if AT_CUDA_ENABLED()
return state->cudaHostAllocator->malloc(nullptr, n);
#else
- (void)n; // avoid unused parameter warning
+ // avoid unused parameter warning
+ (void)state;
+ (void)n;
throw std::runtime_error("pinned memory requires CUDA");
#endif
}
@@ -26,6 +28,8 @@ void PinnedMemoryAllocator::deallocate(void* ptr) const {
#if AT_CUDA_ENABLED()
return state->cudaHostAllocator->free(nullptr, ptr);
#else
+ // avoid unused parameter warning
+ (void)state;
(void)ptr; // avoid unused parameter warning
throw std::runtime_error("pinned memory requires CUDA");
#endif
diff --git a/aten/src/ATen/cudnn/Descriptors.cpp b/aten/src/ATen/cudnn/Descriptors.cpp
index d153447da4..aafaebf163 100644
--- a/aten/src/ATen/cudnn/Descriptors.cpp
+++ b/aten/src/ATen/cudnn/Descriptors.cpp
@@ -1,6 +1,11 @@
#include "Descriptors.h"
+
#include <ATen/ATen.h>
+#include <ostream>
+#include <sstream>
+#include <string>
+
namespace at { namespace native {
namespace {
@@ -63,6 +68,12 @@ std::string cudnnTypeToString(cudnnDataType_t dtype) {
return "CUDNN_DATA_INT32";
case CUDNN_DATA_INT8x4:
return "CUDNN_DATA_INT8x4";
+#if CUDNN_VERSION >= 7100
+ case CUDNN_DATA_UINT8:
+ return "CUDNN_DATA_UINT8";
+ case CUDNN_DATA_UINT8x4:
+ return "CUDNN_DATA_UINT8x4";
+#endif
default:
std::ostringstream oss;
oss << "(unknown data-type " << static_cast<int>(dtype) << ")";
diff --git a/aten/src/ATen/native/Normalization.cpp b/aten/src/ATen/native/Normalization.cpp
index 11b7193d97..3d77e90ed3 100644
--- a/aten/src/ATen/native/Normalization.cpp
+++ b/aten/src/ATen/native/Normalization.cpp
@@ -54,7 +54,9 @@ Tensor batch_norm(
&& input.size(0) <= 131070
&& cudnn_enabled && CUDNN_VERSION >= 5110L);
#else
- (void)cudnn_enabled; // avoid unused parameter warning
+ // avoid unused parameter warning
+ (void)use_cudnn;
+ (void)cudnn_enabled;
#endif
#if AT_CUDNN_ENABLED()
diff --git a/aten/src/ATen/native/cpu/ReduceOpsKernel.cpp b/aten/src/ATen/native/cpu/ReduceOpsKernel.cpp
index 4e4c6d9e2b..cfb4269045 100644
--- a/aten/src/ATen/native/cpu/ReduceOpsKernel.cpp
+++ b/aten/src/ATen/native/cpu/ReduceOpsKernel.cpp
@@ -127,6 +127,7 @@ struct Reduction {
});
if (cols_rounded != cols) {
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
scalar_t buf[WIDTH];
// Initializes the entire (tiny) array to avoid uninitialized warnings
diff --git a/aten/src/TH/THDiskFile.c b/aten/src/TH/THDiskFile.c
index 41cc254f6d..ee06b8bdf8 100644
--- a/aten/src/TH/THDiskFile.c
+++ b/aten/src/TH/THDiskFile.c
@@ -48,10 +48,10 @@ size_t fread__(void *ptr, size_t size, size_t nitems, FILE *stream)
#endif
#define READ_WRITE_METHODS(TYPE, TYPEC, ASCII_READ_ELEM, ASCII_WRITE_ELEM) \
- static size_t THDiskFile_read##TYPEC(THFile *self, TYPE *data, size_t n) \
+ static ssize_t THDiskFile_read##TYPEC(THFile *self, TYPE *data, ssize_t n) \
{ \
THDiskFile *dfself = (THDiskFile*)(self); \
- size_t nread = 0L; \
+ ssize_t nread = 0L; \
\
THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file"); \
THArgCheck(dfself->file.isReadable, 1, "attempt to read in a write-only file"); \
@@ -64,7 +64,7 @@ size_t fread__(void *ptr, size_t size, size_t nitems, FILE *stream)
} \
else \
{ \
- size_t i; \
+ ssize_t i; \
for(i = 0; i < n; i++) \
{ \
ASCII_READ_ELEM; /* increment here result and break if wrong */ \
@@ -87,10 +87,10 @@ size_t fread__(void *ptr, size_t size, size_t nitems, FILE *stream)
return nread; \
} \
\
- static size_t THDiskFile_write##TYPEC(THFile *self, TYPE *data, size_t n) \
+ static ssize_t THDiskFile_write##TYPEC(THFile *self, TYPE *data, ssize_t n) \
{ \
THDiskFile *dfself = (THDiskFile*)(self); \
- size_t nwrite = 0L; \
+ ssize_t nwrite = 0L; \
\
THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file"); \
THArgCheck(dfself->file.isWritable, 1, "attempt to write in a read-only file"); \
@@ -116,7 +116,7 @@ size_t fread__(void *ptr, size_t size, size_t nitems, FILE *stream)
} \
else \
{ \
- size_t i; \
+ ssize_t i; \
for(i = 0; i < n; i++) \
{ \
ASCII_WRITE_ELEM; \
@@ -173,20 +173,20 @@ static void THDiskFile_synchronize(THFile *self)
fflush(dfself->handle);
}
-static void THDiskFile_seek(THFile *self, size_t position)
+static void THDiskFile_seek(THFile *self, ssize_t position)
{
THDiskFile *dfself = (THDiskFile*)(self);
THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
#if defined(_WIN64)
- THArgCheck(position <= (size_t)INT64_MAX, 2, "position must be smaller than INT64_MAX");
+ THArgCheck(position <= INT64_MAX, 2, "position must be smaller than INT64_MAX");
if(_fseeki64(dfself->handle, (int64_t)position, SEEK_SET) < 0)
#elif defined(_WIN32)
- THArgCheck(position <= (size_t)LONG_MAX, 2, "position must be smaller than LONG_MAX");
+ THArgCheck(position <= LONG_MAX, 2, "position must be smaller than LONG_MAX");
if(fseek(dfself->handle, (int32_t)position, SEEK_SET) < 0)
#else
- THArgCheck(position <= (size_t)LLONG_MAX, 2, "position must be smaller than LLONG_MAX");
+ THArgCheck(position <= LLONG_MAX, 2, "position must be smaller than LLONG_MAX");
if(fseeko(dfself->handle, (off_t)position, SEEK_SET) < 0)
#endif
{
@@ -216,7 +216,7 @@ static void THDiskFile_seekEnd(THFile *self)
}
}
-static size_t THDiskFile_position(THFile *self)
+static ssize_t THDiskFile_position(THFile *self)
{
THDiskFile *dfself = (THDiskFile*)(self);
THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
@@ -229,7 +229,7 @@ static size_t THDiskFile_position(THFile *self)
off_t offset = ftello(dfself->handle);
#endif
if (offset > -1)
- return (size_t)offset;
+ return (ssize_t)offset;
else if(!dfself->file.isQuiet)
THError("unable to obtain disk file offset (maybe a long overflow occurred)");
@@ -246,14 +246,14 @@ static void THDiskFile_close(THFile *self)
/* Little and Big Endian */
-static void THDiskFile_reverseMemory(void *dst, const void *src, size_t blockSize, size_t numBlocks)
+static void THDiskFile_reverseMemory(void *dst, const void *src, ssize_t blockSize, ssize_t numBlocks)
{
if(blockSize > 1)
{
- size_t halfBlockSize = blockSize/2;
+ ssize_t halfBlockSize = blockSize/2;
char *charSrc = (char*)src;
char *charDst = (char*)dst;
- size_t b, i;
+ ssize_t b, i;
for(b = 0; b < numBlocks; b++)
{
for(i = 0; i < halfBlockSize; i++)
@@ -369,10 +369,10 @@ READ_WRITE_METHODS(double, Double,
/* For Long we need to rewrite everything, because of the special management of longSize */
-static size_t THDiskFile_readLong(THFile *self, int64_t *data, size_t n)
+static ssize_t THDiskFile_readLong(THFile *self, int64_t *data, ssize_t n)
{
THDiskFile *dfself = (THDiskFile*)(self);
- size_t nread = 0L;
+ ssize_t nread = 0L;
THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
THArgCheck(dfself->file.isReadable, 1, "attempt to read in a write-only file");
@@ -389,7 +389,7 @@ static size_t THDiskFile_readLong(THFile *self, int64_t *data, size_t n)
nread = fread__(data, 4, n, dfself->handle);
if(!dfself->isNativeEncoding && (nread > 0))
THDiskFile_reverseMemory(data, data, 4, nread);
- size_t i;
+ ssize_t i;
for(i = nread; i > 0; i--)
data[i-1] = ((int *)data)[i-1];
}
@@ -398,7 +398,7 @@ static size_t THDiskFile_readLong(THFile *self, int64_t *data, size_t n)
int big_endian = !THDiskFile_isLittleEndianCPU();
int32_t *buffer = THAlloc(8*n);
nread = fread__(buffer, 8, n, dfself->handle);
- size_t i;
+ ssize_t i;
for(i = nread; i > 0; i--)
data[i-1] = buffer[2*(i-1) + big_endian];
THFree(buffer);
@@ -408,7 +408,7 @@ static size_t THDiskFile_readLong(THFile *self, int64_t *data, size_t n)
}
else
{
- size_t i;
+ ssize_t i;
for(i = 0; i < n; i++)
{
int ret = fscanf(dfself->handle, "%" PRId64, &data[i]); if(ret <= 0) break; else nread++;
@@ -431,10 +431,10 @@ static size_t THDiskFile_readLong(THFile *self, int64_t *data, size_t n)
return nread;
}
-static size_t THDiskFile_writeLong(THFile *self, int64_t *data, size_t n)
+static ssize_t THDiskFile_writeLong(THFile *self, int64_t *data, ssize_t n)
{
THDiskFile *dfself = (THDiskFile*)(self);
- size_t nwrite = 0L;
+ ssize_t nwrite = 0L;
THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
THArgCheck(dfself->file.isWritable, 1, "attempt to write in a read-only file");
@@ -457,7 +457,7 @@ static size_t THDiskFile_writeLong(THFile *self, int64_t *data, size_t n)
} else if(dfself->longSize == 4)
{
int32_t *buffer = THAlloc(4*n);
- size_t i;
+ ssize_t i;
for(i = 0; i < n; i++)
buffer[i] = (int32_t) data[i];
if(!dfself->isNativeEncoding)
@@ -469,7 +469,7 @@ static size_t THDiskFile_writeLong(THFile *self, int64_t *data, size_t n)
{
int big_endian = !THDiskFile_isLittleEndianCPU();
int32_t *buffer = THAlloc(8*n);
- size_t i;
+ ssize_t i;
for(i = 0; i < n; i++)
{
buffer[2*i + !big_endian] = 0;
@@ -483,7 +483,7 @@ static size_t THDiskFile_writeLong(THFile *self, int64_t *data, size_t n)
}
else
{
- size_t i;
+ ssize_t i;
for(i = 0; i < n; i++)
{
int ret = fprintf(dfself->handle, "%" PRId64, data[i]); if(ret <= 0) break; else nwrite++;
@@ -504,7 +504,7 @@ static size_t THDiskFile_writeLong(THFile *self, int64_t *data, size_t n)
return nwrite;
}
-static size_t THDiskFile_readString(THFile *self, const char *format, char **str_)
+static ssize_t THDiskFile_readString(THFile *self, const char *format, char **str_)
{
THDiskFile *dfself = (THDiskFile*)(self);
THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
@@ -518,8 +518,8 @@ static size_t THDiskFile_readString(THFile *self, const char *format, char **str
if(format[1] == 'a')
{
char *p = THAlloc(TBRS_BSZ);
- size_t total = TBRS_BSZ;
- size_t pos = 0;
+ ssize_t total = TBRS_BSZ;
+ ssize_t pos = 0;
for (;;)
{
@@ -549,9 +549,9 @@ static size_t THDiskFile_readString(THFile *self, const char *format, char **str
else
{
char *p = THAlloc(TBRS_BSZ);
- size_t total = TBRS_BSZ;
- size_t pos = 0;
- size_t size;
+ ssize_t total = TBRS_BSZ;
+ ssize_t pos = 0;
+ ssize_t size;
for (;;)
{
@@ -594,10 +594,10 @@ static size_t THDiskFile_readString(THFile *self, const char *format, char **str
}
-static size_t THDiskFile_writeString(THFile *self, const char *str, size_t size)
+static ssize_t THDiskFile_writeString(THFile *self, const char *str, ssize_t size)
{
THDiskFile *dfself = (THDiskFile*)(self);
- size_t nwrite;
+ ssize_t nwrite;
THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
THArgCheck(dfself->file.isWritable, 1, "attempt to write in a read-only file");
diff --git a/aten/src/TH/THFilePrivate.h b/aten/src/TH/THFilePrivate.h
index c7f2e8b7c0..93bbaa0287 100644
--- a/aten/src/TH/THFilePrivate.h
+++ b/aten/src/TH/THFilePrivate.h
@@ -21,30 +21,30 @@ struct THFileVTable
{
int (*isOpened)(THFile *self);
- size_t (*readByte)(THFile *self, uint8_t *data, size_t n);
- size_t (*readChar)(THFile *self, int8_t *data, size_t n);
- size_t (*readShort)(THFile *self, int16_t *data, size_t n);
- size_t (*readInt)(THFile *self, int32_t *data, size_t n);
- size_t (*readLong)(THFile *self, int64_t *data, size_t n);
- size_t (*readFloat)(THFile *self, float *data, size_t n);
- size_t (*readDouble)(THFile *self, double *data, size_t n);
- size_t (*readHalf)(THFile *self, THHalf *data, size_t n);
- size_t (*readString)(THFile *self, const char *format, char **str_);
-
- size_t (*writeByte)(THFile *self, uint8_t *data, size_t n);
- size_t (*writeChar)(THFile *self, int8_t *data, size_t n);
- size_t (*writeShort)(THFile *self, int16_t *data, size_t n);
- size_t (*writeInt)(THFile *self, int32_t *data, size_t n);
- size_t (*writeLong)(THFile *self, int64_t *data, size_t n);
- size_t (*writeFloat)(THFile *self, float *data, size_t n);
- size_t (*writeDouble)(THFile *self, double *data, size_t n);
- size_t (*writeHalf)(THFile *self, THHalf *data, size_t n);
- size_t (*writeString)(THFile *self, const char *str, size_t size);
+ ssize_t (*readByte)(THFile *self, uint8_t *data, ssize_t n);
+ ssize_t (*readChar)(THFile *self, int8_t *data, ssize_t n);
+ ssize_t (*readShort)(THFile *self, int16_t *data, ssize_t n);
+ ssize_t (*readInt)(THFile *self, int32_t *data, ssize_t n);
+ ssize_t (*readLong)(THFile *self, int64_t *data, ssize_t n);
+ ssize_t (*readFloat)(THFile *self, float *data, ssize_t n);
+ ssize_t (*readDouble)(THFile *self, double *data, ssize_t n);
+ ssize_t (*readHalf)(THFile *self, THHalf *data, ssize_t n);
+ ssize_t (*readString)(THFile *self, const char *format, char **str_);
+
+ ssize_t (*writeByte)(THFile *self, uint8_t *data, ssize_t n);
+ ssize_t (*writeChar)(THFile *self, int8_t *data, ssize_t n);
+ ssize_t (*writeShort)(THFile *self, int16_t *data, ssize_t n);
+ ssize_t (*writeInt)(THFile *self, int32_t *data, ssize_t n);
+ ssize_t (*writeLong)(THFile *self, int64_t *data, ssize_t n);
+ ssize_t (*writeFloat)(THFile *self, float *data, ssize_t n);
+ ssize_t (*writeDouble)(THFile *self, double *data, ssize_t n);
+ ssize_t (*writeHalf)(THFile *self, THHalf *data, ssize_t n);
+ ssize_t (*writeString)(THFile *self, const char *str, ssize_t size);
void (*synchronize)(THFile *self);
- void (*seek)(THFile *self, size_t position);
+ void (*seek)(THFile *self, ssize_t position);
void (*seekEnd)(THFile *self);
- size_t (*position)(THFile *self);
+ ssize_t (*position)(THFile *self);
void (*close)(THFile *self);
void (*free)(THFile *self);
};
diff --git a/aten/src/TH/THGeneral.c b/aten/src/TH/THGeneral.c
index b6ed9737e6..00c209aec2 100644
--- a/aten/src/TH/THGeneral.c
+++ b/aten/src/TH/THGeneral.c
@@ -159,19 +159,6 @@ void THSetGCHandler( void (*torchGCFunction_)(void *data), void *data )
torchGCData = data;
}
-/* it is guaranteed the allocated size is not bigger than PTRDIFF_MAX */
-static ptrdiff_t getAllocSize(void *ptr) {
-#if defined(__unix) && defined(HAVE_MALLOC_USABLE_SIZE)
- return malloc_usable_size(ptr);
-#elif defined(__APPLE__)
- return malloc_size(ptr);
-#elif defined(_WIN32)
- if(ptr) { return _msize(ptr); } else { return 0; }
-#else
- return 0;
-#endif
-}
-
static void* THAllocInternal(ptrdiff_t size)
{
void *ptr;
diff --git a/aten/src/TH/THMemoryFile.c b/aten/src/TH/THMemoryFile.c
index cbbcfc1f5d..ca86f374e9 100644
--- a/aten/src/TH/THMemoryFile.c
+++ b/aten/src/TH/THMemoryFile.c
@@ -10,8 +10,8 @@ typedef struct THMemoryFile__
{
THFile file;
THCharStorage *storage;
- size_t size;
- size_t position;
+ ssize_t size;
+ ssize_t position;
int longSize;
} THMemoryFile;
@@ -46,9 +46,9 @@ static int8_t *THMemoryFile_strnextspace(int8_t *str_, int8_t *c_)
return NULL;
}
-static void THMemoryFile_grow(THMemoryFile *self, size_t size)
+static void THMemoryFile_grow(THMemoryFile *self, ssize_t size)
{
- size_t missingSpace;
+ ssize_t missingSpace;
if(size <= self->size)
return;
@@ -100,10 +100,10 @@ static int THMemoryFile_mode(const char *mode, int *isReadable, int *isWritable)
/********************************************************/
#define READ_WRITE_METHODS(TYPE, TYPEC, ASCII_READ_ELEM, ASCII_WRITE_ELEM, INSIDE_SPACING) \
- static size_t THMemoryFile_read##TYPEC(THFile *self, TYPE *data, size_t n) \
+ static ssize_t THMemoryFile_read##TYPEC(THFile *self, TYPE *data, ssize_t n) \
{ \
THMemoryFile *mfself = (THMemoryFile*)self; \
- size_t nread = 0; \
+ ssize_t nread = 0; \
\
THArgCheck(mfself->storage != NULL, 1, "attempt to use a closed file"); \
THArgCheck(mfself->file.isReadable, 1, "attempt to read in a write-only file"); \
@@ -113,18 +113,18 @@ static int THMemoryFile_mode(const char *mode, int *isReadable, int *isWritable)
\
if(mfself->file.isBinary) \
{ \
- size_t nByte = sizeof(TYPE)*n; \
- size_t nByteRemaining = (mfself->position + nByte <= mfself->size ? nByte : mfself->size-mfself->position); \
+ ssize_t nByte = sizeof(TYPE)*n; \
+ ssize_t nByteRemaining = (mfself->position + nByte <= mfself->size ? nByte : mfself->size-mfself->position); \
nread = nByteRemaining/sizeof(TYPE); \
memmove(data, mfself->storage->data+mfself->position, nread*sizeof(TYPE)); \
mfself->position += nread*sizeof(TYPE); \
} \
else \
{ \
- size_t i; \
+ ssize_t i; \
for(i = 0; i < n; i++) \
{ \
- size_t nByteRead = 0; \
+ ssize_t nByteRead = 0; \
int8_t spaceChar = 0; \
int8_t *spacePtr = THMemoryFile_strnextspace(mfself->storage->data+mfself->position, &spaceChar); \
ASCII_READ_ELEM; \
@@ -155,7 +155,7 @@ static int THMemoryFile_mode(const char *mode, int *isReadable, int *isWritable)
return nread; \
} \
\
- static size_t THMemoryFile_write##TYPEC(THFile *self, TYPE *data, size_t n) \
+ static ssize_t THMemoryFile_write##TYPEC(THFile *self, TYPE *data, ssize_t n) \
{ \
THMemoryFile *mfself = (THMemoryFile*)self; \
\
@@ -167,7 +167,7 @@ static int THMemoryFile_mode(const char *mode, int *isReadable, int *isWritable)
\
if(mfself->file.isBinary) \
{ \
- size_t nByte = sizeof(TYPE)*n; \
+ ssize_t nByte = sizeof(TYPE)*n; \
THMemoryFile_grow(mfself, mfself->position+nByte); \
memmove(mfself->storage->data+mfself->position, data, nByte); \
mfself->position += nByte; \
@@ -179,7 +179,7 @@ static int THMemoryFile_mode(const char *mode, int *isReadable, int *isWritable)
} \
else \
{ \
- size_t i; \
+ ssize_t i; \
for(i = 0; i < n; i++) \
{ \
ssize_t nByteWritten; \
@@ -243,7 +243,7 @@ static void THMemoryFile_synchronize(THFile *self)
THArgCheck(mfself->storage != NULL, 1, "attempt to use a closed file");
}
-static void THMemoryFile_seek(THFile *self, size_t position)
+static void THMemoryFile_seek(THFile *self, ssize_t position)
{
THMemoryFile *mfself = (THMemoryFile*)self;
@@ -268,7 +268,7 @@ static void THMemoryFile_seekEnd(THFile *self)
mfself->position = mfself->size;
}
-static size_t THMemoryFile_position(THFile *self)
+static ssize_t THMemoryFile_position(THFile *self)
{
THMemoryFile *mfself = (THMemoryFile*)self;
THArgCheck(mfself->storage != NULL, 1, "attempt to use a closed file");
@@ -299,7 +299,7 @@ static void THMemoryFile_free(THFile *self)
/* 1) */
READ_WRITE_METHODS(uint8_t, Byte,
- size_t ret = (mfself->position + n <= mfself->size ? n : mfself->size-mfself->position); \
+ ssize_t ret = (mfself->position + n <= mfself->size ? n : mfself->size-mfself->position); \
if(spacePtr) *spacePtr = spaceChar; \
nByteRead = ret; \
nread = ret; \
@@ -314,7 +314,7 @@ READ_WRITE_METHODS(uint8_t, Byte,
/* DEBUG: we should check if %n is count or not as a element (so ret might need to be ret-- on some systems) */
/* Note that we do a trick for char */
READ_WRITE_METHODS(int8_t, Char,
- size_t ret = (mfself->position + n <= mfself->size ? n : mfself->size-mfself->position); \
+ ssize_t ret = (mfself->position + n <= mfself->size ? n : mfself->size-mfself->position); \
if(spacePtr) *spacePtr = spaceChar; \
nByteRead = ret; \
nread = ret; \
@@ -355,10 +355,10 @@ READ_WRITE_METHODS(double, Double,
int THDiskFile_isLittleEndianCPU(void);
-static size_t THMemoryFile_readLong(THFile *self, int64_t *data, size_t n)
+static ssize_t THMemoryFile_readLong(THFile *self, int64_t *data, ssize_t n)
{
THMemoryFile *mfself = (THMemoryFile*)self;
- size_t nread = 0L;
+ ssize_t nread = 0L;
THArgCheck(mfself->storage != NULL, 1, "attempt to use a closed file");
THArgCheck(mfself->file.isReadable, 1, "attempt to read in a write-only file");
@@ -370,18 +370,18 @@ static size_t THMemoryFile_readLong(THFile *self, int64_t *data, size_t n)
{
if(mfself->longSize == 0 || mfself->longSize == sizeof(int64_t))
{
- size_t nByte = sizeof(int64_t)*n;
- size_t nByteRemaining = (mfself->position + nByte <= mfself->size ? nByte : mfself->size-mfself->position);
+ ssize_t nByte = sizeof(int64_t)*n;
+ ssize_t nByteRemaining = (mfself->position + nByte <= mfself->size ? nByte : mfself->size-mfself->position);
nread = nByteRemaining/sizeof(int64_t);
memmove(data, mfself->storage->data+mfself->position, nread*sizeof(int64_t));
mfself->position += nread*sizeof(int64_t);
} else if(mfself->longSize == 4)
{
- size_t nByte = 4*n;
- size_t nByteRemaining = (mfself->position + nByte <= mfself->size ? nByte : mfself->size-mfself->position);
+ ssize_t nByte = 4*n;
+ ssize_t nByteRemaining = (mfself->position + nByte <= mfself->size ? nByte : mfself->size-mfself->position);
int32_t *storage = (int32_t *)(mfself->storage->data + mfself->position);
nread = nByteRemaining/4;
- size_t i;
+ ssize_t i;
for(i = 0; i < nread; i++)
data[i] = storage[i];
mfself->position += nread*4;
@@ -389,11 +389,11 @@ static size_t THMemoryFile_readLong(THFile *self, int64_t *data, size_t n)
else /* if(mfself->longSize == 8) */
{
int big_endian = !THDiskFile_isLittleEndianCPU();
- size_t nByte = 8*n;
+ ssize_t nByte = 8*n;
int32_t *storage = (int32_t *)(mfself->storage->data + mfself->position);
- size_t nByteRemaining = (mfself->position + nByte <= mfself->size ? nByte : mfself->size-mfself->position);
+ ssize_t nByteRemaining = (mfself->position + nByte <= mfself->size ? nByte : mfself->size-mfself->position);
nread = nByteRemaining/8;
- size_t i;
+ ssize_t i;
for(i = 0; i < nread; i++)
data[i] = storage[2*i + big_endian];
mfself->position += nread*8;
@@ -401,10 +401,10 @@ static size_t THMemoryFile_readLong(THFile *self, int64_t *data, size_t n)
}
else
{
- size_t i;
+ ssize_t i;
for(i = 0; i < n; i++)
{
- size_t nByteRead = 0;
+ ssize_t nByteRead = 0;
int8_t spaceChar = 0;
int8_t *spacePtr = THMemoryFile_strnextspace(mfself->storage->data+mfself->position, &spaceChar);
int nByteRead_; int ret = sscanf((char*) mfself->storage->data+mfself->position, "%" PRId64 "%n", &data[i], &nByteRead_); nByteRead = nByteRead_; if(ret <= 0) break; else nread++;
@@ -435,7 +435,7 @@ static size_t THMemoryFile_readLong(THFile *self, int64_t *data, size_t n)
return nread;
}
-static size_t THMemoryFile_writeLong(THFile *self, int64_t *data, size_t n)
+static ssize_t THMemoryFile_writeLong(THFile *self, int64_t *data, ssize_t n)
{
THMemoryFile *mfself = (THMemoryFile*)self;
@@ -449,16 +449,16 @@ static size_t THMemoryFile_writeLong(THFile *self, int64_t *data, size_t n)
{
if(mfself->longSize == 0 || mfself->longSize == sizeof(int64_t))
{
- size_t nByte = sizeof(int64_t)*n;
+ ssize_t nByte = sizeof(int64_t)*n;
THMemoryFile_grow(mfself, mfself->position+nByte);
memmove(mfself->storage->data+mfself->position, data, nByte);
mfself->position += nByte;
} else if(mfself->longSize == 4)
{
- size_t nByte = 4*n;
+ ssize_t nByte = 4*n;
THMemoryFile_grow(mfself, mfself->position+nByte);
int32_t *storage = (int32_t *)(mfself->storage->data + mfself->position);
- size_t i;
+ ssize_t i;
for(i = 0; i < n; i++)
storage[i] = (int32_t) data[i];
mfself->position += nByte;
@@ -466,10 +466,10 @@ static size_t THMemoryFile_writeLong(THFile *self, int64_t *data, size_t n)
else /* if(mfself->longSize == 8) */
{
int big_endian = !THDiskFile_isLittleEndianCPU();
- size_t nByte = 8*n;
+ ssize_t nByte = 8*n;
THMemoryFile_grow(mfself, mfself->position+nByte);
int32_t *storage = (int32_t *)(mfself->storage->data + mfself->position);
- size_t i;
+ ssize_t i;
for(i = 0; i < n; i++)
{
storage[2*i + !big_endian] = 0;
@@ -485,7 +485,7 @@ static size_t THMemoryFile_writeLong(THFile *self, int64_t *data, size_t n)
}
else
{
- size_t i;
+ ssize_t i;
for(i = 0; i < n; i++)
{
ssize_t nByteWritten;
@@ -525,14 +525,14 @@ static size_t THMemoryFile_writeLong(THFile *self, int64_t *data, size_t n)
return n;
}
-static int8_t* THMemoryFile_cloneString(const int8_t *str, ptrdiff_t size)
+static int8_t* THMemoryFile_cloneString(const int8_t *str, ssize_t size)
{
int8_t *cstr = THAlloc(size);
memcpy(cstr, str, size);
return cstr;
}
-static size_t THMemoryFile_readString(THFile *self, const char *format, char **str_)
+static ssize_t THMemoryFile_readString(THFile *self, const char *format, char **str_)
{
THMemoryFile *mfself = (THMemoryFile*)self;
@@ -552,7 +552,7 @@ static size_t THMemoryFile_readString(THFile *self, const char *format, char **s
if(format[1] == 'a')
{
- size_t str_size = mfself->size-mfself->position;
+ ssize_t str_size = mfself->size-mfself->position;
*str_ = (char*) THMemoryFile_cloneString(mfself->storage->data+mfself->position, str_size);
mfself->position = mfself->size;
@@ -563,8 +563,8 @@ static size_t THMemoryFile_readString(THFile *self, const char *format, char **s
{
int8_t *p = mfself->storage->data+mfself->position;
int eolFound = 0;
- size_t posEol;
- size_t i;
+ ssize_t posEol;
+ ssize_t i;
for(i = 0; i < mfself->size-mfself->position; i++)
{
if(p[i] == '\n')
@@ -583,7 +583,7 @@ static size_t THMemoryFile_readString(THFile *self, const char *format, char **s
}
else /* well, we read all! */
{
- size_t str_size = mfself->size-mfself->position;
+ ssize_t str_size = mfself->size-mfself->position;
*str_ = (char*) THMemoryFile_cloneString(mfself->storage->data+mfself->position, str_size);
mfself->position = mfself->size;
@@ -596,7 +596,7 @@ static size_t THMemoryFile_readString(THFile *self, const char *format, char **s
return 0;
}
-static size_t THMemoryFile_writeString(THFile *self, const char *str, size_t size)
+static ssize_t THMemoryFile_writeString(THFile *self, const char *str, ssize_t size)
{
THMemoryFile *mfself = (THMemoryFile*)self;
diff --git a/aten/src/THNN/generic/SpatialAdaptiveAveragePooling.c b/aten/src/THNN/generic/SpatialAdaptiveAveragePooling.c
index 6e38275789..e71f5b1cf9 100644
--- a/aten/src/THNN/generic/SpatialAdaptiveAveragePooling.c
+++ b/aten/src/THNN/generic/SpatialAdaptiveAveragePooling.c
@@ -74,17 +74,17 @@ void THNN_(SpatialAdaptiveAveragePooling_updateOutput)(
int dimH = 1;
int dimW = 2;
int64_t sizeB = 1;
- int64_t sizeD;
- int64_t isizeH;
- int64_t isizeW;
+ int64_t sizeD = 0;
+ int64_t isizeH = 0;
+ int64_t isizeW = 0;
- int64_t istrideB;
- int64_t istrideD;
- int64_t istrideH;
- int64_t istrideW;
+ int64_t istrideB = 0;
+ int64_t istrideD = 0;
+ int64_t istrideH = 0;
+ int64_t istrideW = 0;
- real *input_data;
- real *output_data;
+ real *input_data = nullptr;
+ real *output_data = nullptr;
THNN_ARGCHECK(input->nDimension == 3 || input->nDimension == 4, 2, input,
diff --git a/aten/src/THNN/generic/SpatialAdaptiveMaxPooling.c b/aten/src/THNN/generic/SpatialAdaptiveMaxPooling.c
index 541dca8128..0255ea9829 100644
--- a/aten/src/THNN/generic/SpatialAdaptiveMaxPooling.c
+++ b/aten/src/THNN/generic/SpatialAdaptiveMaxPooling.c
@@ -83,18 +83,18 @@ void THNN_(SpatialAdaptiveMaxPooling_updateOutput)(
int dimW = 2;
int dimH = 1;
int64_t sizeB = 1;
- int64_t sizeD;
- int64_t isizeH;
- int64_t isizeW;
-
- int64_t istrideD;
- int64_t istrideH;
- int64_t istrideW;
- int64_t istrideB;
-
- real *input_data;
- real *output_data;
- THIndex_t *indices_data;
+ int64_t sizeD = 0;
+ int64_t isizeH = 0;
+ int64_t isizeW = 0;
+
+ int64_t istrideD = 0;
+ int64_t istrideH = 0;
+ int64_t istrideW = 0;
+ int64_t istrideB = 0;
+
+ real *input_data = nullptr;
+ real *output_data = nullptr;
+ THIndex_t *indices_data = nullptr;
THNN_ARGCHECK(input->nDimension == 3 || input->nDimension == 4, 2, input,
diff --git a/aten/src/THNN/generic/VolumetricAdaptiveAveragePooling.c b/aten/src/THNN/generic/VolumetricAdaptiveAveragePooling.c
index 314f62dc2c..01bb9db4aa 100644
--- a/aten/src/THNN/generic/VolumetricAdaptiveAveragePooling.c
+++ b/aten/src/THNN/generic/VolumetricAdaptiveAveragePooling.c
@@ -89,19 +89,19 @@ void THNN_(VolumetricAdaptiveAveragePooling_updateOutput)(
int dimH = 2;
int dimW = 3;
int64_t sizeB = 1;
- int64_t sizeD;
- int64_t isizeT;
- int64_t isizeH;
- int64_t isizeW;
-
- int64_t istrideB;
- int64_t istrideD;
- int64_t istrideT;
- int64_t istrideH;
- int64_t istrideW;
-
- real *input_data;
- real *output_data;
+ int64_t sizeD = 0;
+ int64_t isizeT = 0;
+ int64_t isizeH = 0;
+ int64_t isizeW = 0;
+
+ int64_t istrideB = 0;
+ int64_t istrideD = 0;
+ int64_t istrideT = 0;
+ int64_t istrideH = 0;
+ int64_t istrideW = 0;
+
+ real *input_data = nullptr;
+ real *output_data = nullptr;
THNN_ARGCHECK(input->nDimension == 4 || input->nDimension == 5, 2, input,
diff --git a/aten/src/THNN/generic/VolumetricAdaptiveMaxPooling.c b/aten/src/THNN/generic/VolumetricAdaptiveMaxPooling.c
index 73de996414..6e17e579d9 100644
--- a/aten/src/THNN/generic/VolumetricAdaptiveMaxPooling.c
+++ b/aten/src/THNN/generic/VolumetricAdaptiveMaxPooling.c
@@ -100,20 +100,20 @@ void THNN_(VolumetricAdaptiveMaxPooling_updateOutput)(
int dimH = 2;
int dimW = 3;
int64_t sizeB = 1;
- int64_t sizeD;
- int64_t isizeT;
- int64_t isizeH;
- int64_t isizeW;
-
- int64_t istrideB;
- int64_t istrideD;
- int64_t istrideT;
- int64_t istrideH;
- int64_t istrideW;
-
- real *input_data;
- real *output_data;
- THIndex_t *indices_data;
+ int64_t sizeD = 0;
+ int64_t isizeT = 0;
+ int64_t isizeH = 0;
+ int64_t isizeW = 0;
+
+ int64_t istrideB = 0;
+ int64_t istrideD = 0;
+ int64_t istrideT = 0;
+ int64_t istrideH = 0;
+ int64_t istrideW = 0;
+
+ real *input_data = nullptr;
+ real *output_data = nullptr;
+ THIndex_t *indices_data = nullptr;
THNN_ARGCHECK(input->nDimension == 4 || input->nDimension == 5, 2, input,
"4D or 5D (batch mode) tensor expected for input, but got: %s");