# Question about conv2D in Android NN: the output shape limit

0

When I was trying the android nn code, found these in Conv2D.cpp:

``````tflite::Dims<4> im2colDim;                                                    \
im2colDim.sizes = (int)getSizeOfDimension(outputShape, 0);                 \
im2colDim.sizes = (int)getSizeOfDimension(outputShape, 1);                 \
im2colDim.sizes = (int)getSizeOfDimension(outputShape, 2);                 \
im2colDim.sizes = (int)inDepth * filterHeight * filterWidth;               \
\
im2colDim.strides = 1;                                                     \
for (int i = 1; i < 4; i++) {                                                 \
im2colDim.strides[i] = im2colDim.strides[i - 1] * im2colDim.sizes[i - 1]; \
}                                                                             \
\
Type* im2colData = nullptr;                                                   \
uint64_t im2colByteSize = sizeof(Type);                                       \
std::unique_ptr<Type[]> im2colGuard;                                          \
for (int i = 0; i < 4; i++) {                                                 \
im2colByteSize *= im2colDim.sizes[i];                                     \
}                                                                             \
/* http://b/77982879, tflite::optimized_ops::Conv uses int for offsets */     \
if (im2colByteSize >= 0x7fffffff) {                                           \
LOG(ERROR) << "Conv size is too large, not enough memory";                \
return false;                                                             \
}                                                                             \
if (im2colByteSize <= kStaticBufferSize) {                                    \
im2colData = reinterpret_cast<Type*>(static_scratch_buffer);              \
} else {                                                                      \
im2colData = new (std::nothrow) Type[im2colByteSize / sizeof(Type)];      \
if (im2colData == nullptr) {                                              \
LOG(ERROR) << "Conv size is too large, not enough memory";            \
return false;                                                         \
}                                                                         \
im2colGuard.reset(im2colData);                                            \
}
``````

I wonder why the byteSize has to be checked?

around line 163

thanks guys

android
deep-learning
neural-network
tensorflow-lite
nnapi
{"ft_lang_label":"__label__en","ft_lang_prob":0.58537465,"math_prob":0.99027383,"size":1838,"snap":"2021-31-2021-39","text_gpt3_token_len":572,"char_repetition_ratio":0.15049073,"word_repetition_ratio":0.129771,"special_character_ratio":0.3117519,"punctuation_ratio":0.19937694,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9757422,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-16T19:30:28Z\",\"WARC-Record-ID\":\"<urn:uuid:ec4b4b61-1bfb-46f4-aa0b-73299454569d>\",\"Content-Length\":\"7709\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e70a64bb-7fad-40e0-8c7b-83895cf821a2>\",\"WARC-Concurrent-To\":\"<urn:uuid:f4d6d294-859f-4d19-9ea8-c3cdc2f45fc9>\",\"WARC-IP-Address\":\"45.56.93.6\",\"WARC-Target-URI\":\"https://windows-hexerror.linestarve.com/q/so61792033-question-about-conv2d-in-android-nn-the-output-shape-limit\",\"WARC-Payload-Digest\":\"sha1:HTVZBYYLGPFO5JQO2QDXO3B4NLGNWXA7\",\"WARC-Block-Digest\":\"sha1:AOMOSZZ42A2RNFNVHS2FA6MM23RGME35\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780053717.37_warc_CC-MAIN-20210916174455-20210916204455-00622.warc.gz\"}"}