You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_cast.cpp 17 kB

adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
adreno image shader + fp16 + fp16a (#1714) * wip * wip * fix * image and imageview can not be destroyed until command execution ends * fast copy path for tightly packed data * wip * texture load works * 1d 3d image * record clone image, multiple commands share one image reference * upload download image * layer forward accept vkimagemat * vkimagemat graph works * staging vkimagemat for passing dynamic parameters, macro for fp32+image shader, padding image shader * vkimagemat elemsize * convolution test pass * conv1x1s1 image shader * fast staging image allocator from host memory, pooling image shader * convolutiondepthwise image shader * innerproduct image shader * packing image shader * crop deconvolution image shader * resolve spirv binding types * image fp16 and fp16a, cast image shader * eltwise image shader * wip * absval image shader * deconvolutiondepthwise image shader * concat image shader, squeezenet works * noop split image shader * uniform precision hint * layer support_image_storage * wip * vulkan device utility operator * command is storage and packing option aware * fallback to cpu on image allocation failed, mobilenetssd works * flatten image shader, enable more test * ci test * check imgfp32 imgfp16 imgfp16a features * fix ci test * fix ci test * upgrade swiftshader * wip * opt aggressive * imgfp16p * opt none * convolution winograd image shader * fix flush range, fast copy path for continous buffer * minor fix * fix innerproduct * wip ... * wip * cast fix * packing test * wip * image fp16p is fp16p * wip * silence * more line info * code clean * softmax image shader
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // https://opensource.org/licenses/BSD-3-Clause
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed
  11. // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. // CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. // specific language governing permissions and limitations under the License.
  14. #include "testutil.h"
  15. static int cast_cpu_naive(const ncnn::Mat& a, ncnn::Mat& b, int type_from, int type_to)
  16. {
  17. ncnn::ParamDict pd;
  18. pd.set(0, type_from);
  19. pd.set(1, type_to);
  20. std::vector<ncnn::Mat> weights(0);
  21. ncnn::Option opt;
  22. opt.num_threads = 1;
  23. ncnn::Layer* op = ncnn::create_layer_naive("Cast");
  24. op->load_param(pd);
  25. ncnn::ModelBinFromMatArray mb(weights.data());
  26. op->load_model(mb);
  27. op->create_pipeline(opt);
  28. op->forward(a, b, opt);
  29. op->destroy_pipeline(opt);
  30. delete op;
  31. return 0;
  32. }
  33. static int test_cast_cpu(const ncnn::Mat& a, int type_from, int type_to)
  34. {
  35. ncnn::ParamDict pd;
  36. pd.set(0, type_from);
  37. pd.set(1, type_to);
  38. std::vector<ncnn::Mat> weights(0);
  39. ncnn::Option opt;
  40. opt.num_threads = 1;
  41. opt.use_vulkan_compute = false;
  42. opt.use_int8_inference = false;
  43. opt.use_packing_layout = false;
  44. ncnn::Layer* op = ncnn::create_layer_cpu("Cast");
  45. op->load_param(pd);
  46. ncnn::ModelBinFromMatArray mb(weights.data());
  47. op->load_model(mb);
  48. op->create_pipeline(opt);
  49. ncnn::Mat a_fp16;
  50. cast_cpu_naive(a, a_fp16, 1, type_from);
  51. ncnn::Mat b;
  52. cast_cpu_naive(a_fp16, b, type_from, type_to);
  53. ncnn::Mat c;
  54. op->forward(a_fp16, c, opt);
  55. op->destroy_pipeline(opt);
  56. delete op;
  57. if (CompareMat(b, c, 0.001) != 0)
  58. {
  59. fprintf(stderr, "test_cast_cpu failed a.dims=%d a=(%d %d %d %d) type_from=%d type_to=%d\n", a.dims, a.w, a.h, a.d, a.c, type_from, type_to);
  60. return -1;
  61. }
  62. return 0;
  63. }
  64. static int test_cast_cpu_packed(const ncnn::Mat& a, int type_from, int type_to)
  65. {
  66. ncnn::ParamDict pd;
  67. pd.set(0, type_from);
  68. pd.set(1, type_to);
  69. std::vector<ncnn::Mat> weights(0);
  70. ncnn::Option opt;
  71. opt.num_threads = 1;
  72. opt.use_vulkan_compute = false;
  73. opt.use_packing_layout = false;
  74. ncnn::Layer* op = ncnn::create_layer_cpu("Cast");
  75. op->load_param(pd);
  76. ncnn::ModelBinFromMatArray mb(weights.data());
  77. op->load_model(mb);
  78. op->create_pipeline(opt);
  79. ncnn::Mat a_fp16;
  80. cast_cpu_naive(a, a_fp16, 1, type_from);
  81. ncnn::Mat b;
  82. cast_cpu_naive(a_fp16, b, type_from, type_to);
  83. ncnn::Mat a4;
  84. ncnn::convert_packing(a, a4, 4, opt);
  85. ncnn::Mat a4_fp16;
  86. cast_cpu_naive(a4, a4_fp16, 1, type_from);
  87. ncnn::Mat c;
  88. op->forward(a4_fp16, c, opt);
  89. op->destroy_pipeline(opt);
  90. delete op;
  91. if (CompareMat(b, c, 0.001) != 0)
  92. {
  93. fprintf(stderr, "test_cast_cpu_packed failed a.dims=%d a=(%d %d %d %d) type_from=%d type_to=%d\n", a.dims, a.w, a.h, a.d, a.c, type_from, type_to);
  94. return -1;
  95. }
  96. return 0;
  97. }
  98. #if NCNN_VULKAN
  99. static int test_cast_gpu_fp16p(const ncnn::Mat& a, int type_from, int type_to)
  100. {
  101. if (type_to == 4 || type_from == 4)
  102. return 0;
  103. ncnn::ParamDict pd;
  104. pd.set(0, type_from);
  105. pd.set(1, type_to);
  106. std::vector<ncnn::Mat> weights(0);
  107. ncnn::Option opt;
  108. opt.num_threads = 1;
  109. opt.use_vulkan_compute = true;
  110. opt.use_int8_inference = false;
  111. opt.use_fp16_packed = true;
  112. opt.use_fp16_storage = false;
  113. opt.use_fp16_arithmetic = false;
  114. opt.use_int8_storage = false;
  115. opt.use_int8_arithmetic = false;
  116. opt.use_packing_layout = true;
  117. opt.use_image_storage = false;
  118. ncnn::VulkanDevice* vkdev = ncnn::get_gpu_device();
  119. ncnn::VkAllocator* blob_vkallocator = vkdev->acquire_blob_allocator();
  120. ncnn::VkAllocator* staging_vkallocator = vkdev->acquire_staging_allocator();
  121. opt.blob_vkallocator = blob_vkallocator;
  122. opt.workspace_vkallocator = blob_vkallocator;
  123. opt.staging_vkallocator = staging_vkallocator;
  124. if (!vkdev->info.support_fp16_packed()) opt.use_fp16_packed = false;
  125. if (!vkdev->info.support_fp16_storage()) opt.use_fp16_storage = false;
  126. ncnn::Layer* op = ncnn::create_layer_vulkan("Cast");
  127. op->vkdev = vkdev;
  128. op->load_param(pd);
  129. ncnn::ModelBinFromMatArray mb(weights.data());
  130. op->load_model(mb);
  131. op->create_pipeline(opt);
  132. ncnn::Mat a_fp16;
  133. if (type_from == 2)
  134. {
  135. ncnn::cast_float32_to_float16(a, a_fp16, opt);
  136. }
  137. else
  138. {
  139. a_fp16 = a;
  140. }
  141. ncnn::Mat b;
  142. cast_cpu_naive(a_fp16, b, type_from, type_to);
  143. ncnn::Mat d;
  144. // pack
  145. ncnn::Mat a4;
  146. ncnn::convert_packing(a, a4, 4, opt);
  147. ncnn::Mat a4_fp16;
  148. if (type_from == 2 && a4.elempack == 4)
  149. {
  150. ncnn::cast_float32_to_float16(a4, a4_fp16, opt);
  151. }
  152. else
  153. {
  154. a4_fp16 = a4;
  155. }
  156. // forward
  157. ncnn::VkCompute cmd(vkdev);
  158. // upload
  159. ncnn::VkMat a4_gpu;
  160. cmd.record_clone(a4_fp16, a4_gpu, opt);
  161. ncnn::VkMat d4_gpu;
  162. if (op->support_inplace)
  163. {
  164. op->forward_inplace(a4_gpu, cmd, opt);
  165. d4_gpu = a4_gpu;
  166. }
  167. else
  168. {
  169. op->forward(a4_gpu, d4_gpu, cmd, opt);
  170. }
  171. // download
  172. cmd.record_clone(d4_gpu, d, opt);
  173. cmd.submit_and_wait();
  174. op->destroy_pipeline(opt);
  175. delete op;
  176. vkdev->reclaim_blob_allocator(blob_vkallocator);
  177. vkdev->reclaim_staging_allocator(staging_vkallocator);
  178. if (CompareMat(b, d, 0.001) != 0)
  179. {
  180. fprintf(stderr, "test_cast_gpu_fp16p failed a.dims=%d a=(%d %d %d %d) type_from=%d type_to=%d\n", a.dims, a.w, a.h, a.d, a.c, type_from, type_to);
  181. return -1;
  182. }
  183. return 0;
  184. }
  185. static int test_cast_gpu_fp16p_pack8(const ncnn::Mat& a, int type_from, int type_to)
  186. {
  187. if (type_to == 4 || type_from == 4)
  188. return 0;
  189. ncnn::ParamDict pd;
  190. pd.set(0, type_from);
  191. pd.set(1, type_to);
  192. std::vector<ncnn::Mat> weights(0);
  193. ncnn::Option opt;
  194. opt.num_threads = 1;
  195. opt.use_vulkan_compute = true;
  196. opt.use_int8_inference = false;
  197. opt.use_fp16_packed = true;
  198. opt.use_fp16_storage = false;
  199. opt.use_fp16_arithmetic = false;
  200. opt.use_int8_storage = false;
  201. opt.use_int8_arithmetic = false;
  202. opt.use_packing_layout = true;
  203. opt.use_shader_pack8 = true;
  204. opt.use_image_storage = false;
  205. ncnn::VulkanDevice* vkdev = ncnn::get_gpu_device();
  206. ncnn::VkAllocator* blob_vkallocator = vkdev->acquire_blob_allocator();
  207. ncnn::VkAllocator* staging_vkallocator = vkdev->acquire_staging_allocator();
  208. opt.blob_vkallocator = blob_vkallocator;
  209. opt.workspace_vkallocator = blob_vkallocator;
  210. opt.staging_vkallocator = staging_vkallocator;
  211. if (!vkdev->info.support_fp16_packed()) opt.use_fp16_packed = false;
  212. if (!vkdev->info.support_fp16_storage()) opt.use_fp16_storage = false;
  213. ncnn::Layer* op = ncnn::create_layer_vulkan("Cast");
  214. op->vkdev = vkdev;
  215. op->load_param(pd);
  216. ncnn::ModelBinFromMatArray mb(weights.data());
  217. op->load_model(mb);
  218. op->create_pipeline(opt);
  219. ncnn::Mat a_fp16;
  220. if (type_from == 2)
  221. {
  222. ncnn::cast_float32_to_float16(a, a_fp16, opt);
  223. }
  224. else
  225. {
  226. a_fp16 = a;
  227. }
  228. ncnn::Mat b;
  229. cast_cpu_naive(a_fp16, b, type_from, type_to);
  230. ncnn::Mat d;
  231. // pack
  232. ncnn::Mat a4;
  233. ncnn::convert_packing(a, a4, 8, opt);
  234. if (a4.elempack != 8)
  235. ncnn::convert_packing(a, a4, 4, opt);
  236. ncnn::Mat a4_fp16;
  237. if (type_from == 2 && (a4.elempack == 4 || a4.elempack == 8))
  238. {
  239. ncnn::cast_float32_to_float16(a4, a4_fp16, opt);
  240. }
  241. else
  242. {
  243. a4_fp16 = a4;
  244. }
  245. // forward
  246. ncnn::VkCompute cmd(vkdev);
  247. // upload
  248. ncnn::VkMat a4_gpu;
  249. cmd.record_clone(a4_fp16, a4_gpu, opt);
  250. ncnn::VkMat d4_gpu;
  251. if (op->support_inplace)
  252. {
  253. op->forward_inplace(a4_gpu, cmd, opt);
  254. d4_gpu = a4_gpu;
  255. }
  256. else
  257. {
  258. op->forward(a4_gpu, d4_gpu, cmd, opt);
  259. }
  260. // download
  261. cmd.record_clone(d4_gpu, d, opt);
  262. cmd.submit_and_wait();
  263. op->destroy_pipeline(opt);
  264. delete op;
  265. vkdev->reclaim_blob_allocator(blob_vkallocator);
  266. vkdev->reclaim_staging_allocator(staging_vkallocator);
  267. if (CompareMat(b, d, 0.001) != 0)
  268. {
  269. fprintf(stderr, "test_cast_gpu_fp16p_pack8 failed a.dims=%d a=(%d %d %d %d) type_from=%d type_to=%d\n", a.dims, a.w, a.h, a.d, a.c, type_from, type_to);
  270. return -1;
  271. }
  272. return 0;
  273. }
  274. static int test_cast_gpu_image_fp16p(const ncnn::Mat& a, int type_from, int type_to)
  275. {
  276. if (type_to == 4 || type_from == 4)
  277. return 0;
  278. ncnn::ParamDict pd;
  279. pd.set(0, type_from);
  280. pd.set(1, type_to);
  281. std::vector<ncnn::Mat> weights(0);
  282. ncnn::Option opt;
  283. opt.num_threads = 1;
  284. opt.use_vulkan_compute = true;
  285. opt.use_int8_inference = false;
  286. opt.use_fp16_packed = true;
  287. opt.use_fp16_storage = false;
  288. opt.use_fp16_arithmetic = false;
  289. opt.use_int8_storage = false;
  290. opt.use_int8_arithmetic = false;
  291. opt.use_packing_layout = true;
  292. opt.use_image_storage = true;
  293. ncnn::VulkanDevice* vkdev = ncnn::get_gpu_device();
  294. ncnn::VkAllocator* blob_vkallocator = vkdev->acquire_blob_allocator();
  295. ncnn::VkAllocator* staging_vkallocator = vkdev->acquire_staging_allocator();
  296. opt.blob_vkallocator = blob_vkallocator;
  297. opt.workspace_vkallocator = blob_vkallocator;
  298. opt.staging_vkallocator = staging_vkallocator;
  299. if (!vkdev->info.support_fp16_packed()) opt.use_fp16_packed = false;
  300. if (!vkdev->info.support_fp16_storage()) opt.use_fp16_storage = false;
  301. ncnn::Layer* op = ncnn::create_layer_vulkan("Cast");
  302. op->vkdev = vkdev;
  303. op->load_param(pd);
  304. ncnn::ModelBinFromMatArray mb(weights.data());
  305. op->load_model(mb);
  306. op->create_pipeline(opt);
  307. ncnn::Mat a_fp16;
  308. if (type_from == 2)
  309. {
  310. ncnn::cast_float32_to_float16(a, a_fp16, opt);
  311. }
  312. else
  313. {
  314. a_fp16 = a;
  315. }
  316. ncnn::Mat b;
  317. cast_cpu_naive(a_fp16, b, type_from, type_to);
  318. ncnn::Mat d;
  319. // pack
  320. ncnn::Mat a4;
  321. ncnn::convert_packing(a, a4, 4, opt);
  322. ncnn::Mat a4_fp16;
  323. if (type_from == 2 && a4.elempack == 4)
  324. {
  325. ncnn::cast_float32_to_float16(a4, a4_fp16, opt);
  326. }
  327. else
  328. {
  329. a4_fp16 = a4;
  330. }
  331. // forward
  332. ncnn::VkCompute cmd(vkdev);
  333. // upload
  334. ncnn::VkImageMat a4_gpu;
  335. cmd.record_clone(a4_fp16, a4_gpu, opt);
  336. ncnn::VkImageMat d4_gpu;
  337. if (op->support_inplace)
  338. {
  339. op->forward_inplace(a4_gpu, cmd, opt);
  340. d4_gpu = a4_gpu;
  341. }
  342. else
  343. {
  344. op->forward(a4_gpu, d4_gpu, cmd, opt);
  345. }
  346. // download
  347. cmd.record_clone(d4_gpu, d, opt);
  348. cmd.submit_and_wait();
  349. op->destroy_pipeline(opt);
  350. delete op;
  351. vkdev->reclaim_blob_allocator(blob_vkallocator);
  352. vkdev->reclaim_staging_allocator(staging_vkallocator);
  353. if (CompareMat(b, d, 0.001) != 0)
  354. {
  355. fprintf(stderr, "test_cast_gpu_image_fp16p failed a.dims=%d a=(%d %d %d %d) type_from=%d type_to=%d\n", a.dims, a.w, a.h, a.d, a.c, type_from, type_to);
  356. return -1;
  357. }
  358. return 0;
  359. }
  360. static int test_cast_gpu_image_fp16p_pack8(const ncnn::Mat& a, int type_from, int type_to)
  361. {
  362. if (type_to == 4 || type_from == 4)
  363. return 0;
  364. ncnn::ParamDict pd;
  365. pd.set(0, type_from);
  366. pd.set(1, type_to);
  367. std::vector<ncnn::Mat> weights(0);
  368. ncnn::Option opt;
  369. opt.num_threads = 1;
  370. opt.use_vulkan_compute = true;
  371. opt.use_int8_inference = false;
  372. opt.use_fp16_packed = true;
  373. opt.use_fp16_storage = false;
  374. opt.use_fp16_arithmetic = false;
  375. opt.use_int8_storage = false;
  376. opt.use_int8_arithmetic = false;
  377. opt.use_packing_layout = true;
  378. opt.use_shader_pack8 = true;
  379. opt.use_image_storage = true;
  380. ncnn::VulkanDevice* vkdev = ncnn::get_gpu_device();
  381. ncnn::VkAllocator* blob_vkallocator = vkdev->acquire_blob_allocator();
  382. ncnn::VkAllocator* staging_vkallocator = vkdev->acquire_staging_allocator();
  383. opt.blob_vkallocator = blob_vkallocator;
  384. opt.workspace_vkallocator = blob_vkallocator;
  385. opt.staging_vkallocator = staging_vkallocator;
  386. if (!vkdev->info.support_fp16_packed()) opt.use_fp16_packed = false;
  387. if (!vkdev->info.support_fp16_storage()) opt.use_fp16_storage = false;
  388. ncnn::Layer* op = ncnn::create_layer_vulkan("Cast");
  389. op->vkdev = vkdev;
  390. op->load_param(pd);
  391. ncnn::ModelBinFromMatArray mb(weights.data());
  392. op->load_model(mb);
  393. op->create_pipeline(opt);
  394. ncnn::Mat a_fp16;
  395. if (type_from == 2)
  396. {
  397. ncnn::cast_float32_to_float16(a, a_fp16, opt);
  398. }
  399. else
  400. {
  401. a_fp16 = a;
  402. }
  403. ncnn::Mat b;
  404. cast_cpu_naive(a_fp16, b, type_from, type_to);
  405. ncnn::Mat d;
  406. // pack
  407. ncnn::Mat a4;
  408. ncnn::convert_packing(a, a4, 8, opt);
  409. if (a4.elempack != 8)
  410. ncnn::convert_packing(a, a4, 4, opt);
  411. ncnn::Mat a4_fp16;
  412. if (type_from == 2 && (a4.elempack == 4 || a4.elempack == 8))
  413. {
  414. ncnn::cast_float32_to_float16(a4, a4_fp16, opt);
  415. }
  416. else
  417. {
  418. a4_fp16 = a4;
  419. }
  420. // forward
  421. ncnn::VkCompute cmd(vkdev);
  422. // upload
  423. ncnn::VkImageMat a4_gpu;
  424. cmd.record_clone(a4_fp16, a4_gpu, opt);
  425. ncnn::VkImageMat d4_gpu;
  426. if (op->support_inplace)
  427. {
  428. op->forward_inplace(a4_gpu, cmd, opt);
  429. d4_gpu = a4_gpu;
  430. }
  431. else
  432. {
  433. op->forward(a4_gpu, d4_gpu, cmd, opt);
  434. }
  435. // download
  436. cmd.record_clone(d4_gpu, d, opt);
  437. cmd.submit_and_wait();
  438. op->destroy_pipeline(opt);
  439. delete op;
  440. vkdev->reclaim_blob_allocator(blob_vkallocator);
  441. vkdev->reclaim_staging_allocator(staging_vkallocator);
  442. if (CompareMat(b, d, 0.001) != 0)
  443. {
  444. fprintf(stderr, "test_cast_gpu_image_fp16p_pack8 failed a.dims=%d a=(%d %d %d %d) type_from=%d type_to=%d\n", a.dims, a.w, a.h, a.d, a.c, type_from, type_to);
  445. return -1;
  446. }
  447. return 0;
  448. }
  449. #endif // NCNN_VULKAN
  450. static int test_cast(const ncnn::Mat& a, int type_from, int type_to)
  451. {
  452. return 0
  453. || test_cast_cpu(a, type_from, type_to)
  454. || test_cast_cpu_packed(a, type_from, type_to)
  455. #if NCNN_VULKAN
  456. || test_cast_gpu_fp16p(a, type_from, type_to)
  457. || test_cast_gpu_fp16p_pack8(a, type_from, type_to)
  458. || test_cast_gpu_image_fp16p(a, type_from, type_to)
  459. || test_cast_gpu_image_fp16p_pack8(a, type_from, type_to)
  460. #endif // NCNN_VULKAN
  461. ;
  462. }
  463. static int test_cast_0()
  464. {
  465. return 0
  466. || test_cast(RandomMat(5, 6, 7, 16), 1, 2)
  467. || test_cast(RandomMat(3, 4, 5, 13), 1, 2)
  468. || test_cast(RandomMat(5, 6, 7, 16), 2, 1)
  469. || test_cast(RandomMat(3, 4, 5, 13), 2, 1)
  470. || test_cast(RandomMat(5, 6, 7, 16), 1, 4)
  471. || test_cast(RandomMat(3, 4, 5, 13), 1, 4)
  472. || test_cast(RandomMat(5, 6, 7, 16), 4, 1)
  473. || test_cast(RandomMat(3, 4, 5, 13), 4, 1);
  474. }
  475. static int test_cast_1()
  476. {
  477. return 0
  478. || test_cast(RandomMat(5, 7, 16), 1, 2)
  479. || test_cast(RandomMat(3, 5, 13), 1, 2)
  480. || test_cast(RandomMat(5, 7, 16), 2, 1)
  481. || test_cast(RandomMat(3, 5, 13), 2, 1)
  482. || test_cast(RandomMat(5, 7, 16), 1, 4)
  483. || test_cast(RandomMat(3, 5, 13), 1, 4)
  484. || test_cast(RandomMat(5, 7, 16), 4, 1)
  485. || test_cast(RandomMat(3, 5, 13), 4, 1);
  486. }
  487. static int test_cast_2()
  488. {
  489. return 0
  490. || test_cast(RandomMat(6, 16), 1, 2)
  491. || test_cast(RandomMat(7, 15), 1, 2)
  492. || test_cast(RandomMat(6, 16), 2, 1)
  493. || test_cast(RandomMat(7, 15), 2, 1)
  494. || test_cast(RandomMat(6, 16), 1, 4)
  495. || test_cast(RandomMat(7, 15), 1, 4)
  496. || test_cast(RandomMat(6, 16), 4, 1)
  497. || test_cast(RandomMat(7, 15), 4, 1);
  498. }
  499. static int test_cast_3()
  500. {
  501. return 0
  502. || test_cast(RandomMat(128), 1, 2)
  503. || test_cast(RandomMat(127), 1, 2)
  504. || test_cast(RandomMat(128), 2, 1)
  505. || test_cast(RandomMat(127), 2, 1)
  506. || test_cast(RandomMat(128), 1, 4)
  507. || test_cast(RandomMat(127), 1, 4)
  508. || test_cast(RandomMat(128), 4, 1)
  509. || test_cast(RandomMat(127), 4, 1);
  510. }
  511. int main()
  512. {
  513. SRAND(7767517);
  514. return 0
  515. || test_cast_0()
  516. || test_cast_1()
  517. || test_cast_2()
  518. || test_cast_3();
  519. }