| @@ -17,6 +17,7 @@ | |||
| #if NCNN_VULKAN | |||
| #include <stdio.h> | |||
| #include "option.h" | |||
| namespace ncnn { | |||
| @@ -841,16 +842,16 @@ VkTransfer::~VkTransfer() | |||
| { | |||
| } | |||
| void VkTransfer::record_upload(const Mat& src, VkMat& dst) | |||
| void VkTransfer::record_upload(const Mat& src, VkMat& dst, const Option& opt) | |||
| { | |||
| if (src.elemsize / src.packing == 4) | |||
| { | |||
| if (vkdev->info.support_fp16_storage || (vkdev->info.support_fp16_packed && src.packing % 4 == 0)) | |||
| if (opt.use_fp16_storage || (opt.use_fp16_packed && src.packing % 4 == 0)) | |||
| { | |||
| Mat src_fp16; | |||
| cast_float32_to_float16(src, src_fp16); | |||
| record_upload(src_fp16, dst); | |||
| record_upload(src_fp16, dst, opt); | |||
| return; | |||
| } | |||
| @@ -173,7 +173,7 @@ public: | |||
| VkTransfer(const VulkanDevice* vkdev); | |||
| ~VkTransfer(); | |||
| void record_upload(const Mat& src, VkMat& dst); | |||
| void record_upload(const Mat& src, VkMat& dst, const Option& opt); | |||
| int submit_and_wait(); | |||
| @@ -101,7 +101,7 @@ int Layer::forward_inplace(Mat& /*bottom_top_blob*/, const Option& /*opt*/) cons | |||
| } | |||
| #if NCNN_VULKAN | |||
| int Layer::upload_model(VkTransfer& /*cmd*/) | |||
| int Layer::upload_model(VkTransfer& /*cmd*/, const Option& /*opt*/) | |||
| { | |||
| return 0; | |||
| } | |||
| @@ -79,7 +79,7 @@ public: | |||
| #if NCNN_VULKAN | |||
| public: | |||
| // upload weight blob from host to device | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt = Option()); | |||
| public: | |||
| // implement inference | |||
| @@ -34,14 +34,14 @@ int AbsVal_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_absval = new Pipeline(vkdev); | |||
| pipeline_absval->set_optimal_local_size_xyz(); | |||
| pipeline_absval->create("absval", specializations, 1, 5); | |||
| pipeline_absval->create("absval", opt, specializations, 1, 5); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_absval_pack4 = new Pipeline(vkdev); | |||
| pipeline_absval_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_absval_pack4->create("absval_pack4", specializations, 1, 5); | |||
| pipeline_absval_pack4->create("absval_pack4", opt, specializations, 1, 5); | |||
| } | |||
| return 0; | |||
| @@ -37,7 +37,7 @@ int BatchNorm_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_batchnorm = new Pipeline(vkdev); | |||
| pipeline_batchnorm->set_optimal_local_size_xyz(32, 32, channels); | |||
| pipeline_batchnorm->create("batchnorm", specializations, 3, 5); | |||
| pipeline_batchnorm->create("batchnorm", opt, specializations, 3, 5); | |||
| } | |||
| // pack4 | |||
| @@ -45,7 +45,7 @@ int BatchNorm_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_batchnorm_pack4 = new Pipeline(vkdev); | |||
| pipeline_batchnorm_pack4->set_optimal_local_size_xyz(32, 32, channels / 4); | |||
| pipeline_batchnorm_pack4->create("batchnorm_pack4", specializations, 3, 5); | |||
| pipeline_batchnorm_pack4->create("batchnorm_pack4", opt, specializations, 3, 5); | |||
| } | |||
| return 0; | |||
| @@ -62,13 +62,13 @@ int BatchNorm_vulkan::destroy_pipeline(const Option& opt) | |||
| return 0; | |||
| } | |||
| int BatchNorm_vulkan::upload_model(VkTransfer& cmd) | |||
| int BatchNorm_vulkan::upload_model(VkTransfer& cmd, const Option& opt) | |||
| { | |||
| // pack1 | |||
| if (channels % 4 != 0) | |||
| { | |||
| cmd.record_upload(a_data, a_data_gpu); | |||
| cmd.record_upload(b_data, b_data_gpu); | |||
| cmd.record_upload(a_data, a_data_gpu, opt); | |||
| cmd.record_upload(b_data, b_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -76,11 +76,11 @@ int BatchNorm_vulkan::upload_model(VkTransfer& cmd) | |||
| { | |||
| Mat a_data_pack4; | |||
| convert_packing(a_data, a_data_pack4, 4); | |||
| cmd.record_upload(a_data_pack4, a_data_gpu_pack4); | |||
| cmd.record_upload(a_data_pack4, a_data_gpu_pack4, opt); | |||
| Mat b_data_pack4; | |||
| convert_packing(b_data, b_data_pack4, 4); | |||
| cmd.record_upload(b_data_pack4, b_data_gpu_pack4); | |||
| cmd.record_upload(b_data_pack4, b_data_gpu_pack4, opt); | |||
| } | |||
| return 0; | |||
| @@ -27,7 +27,7 @@ public: | |||
| virtual int create_pipeline(const Option& opt); | |||
| virtual int destroy_pipeline(const Option& opt); | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt); | |||
| virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const; | |||
| @@ -40,14 +40,14 @@ int BinaryOp_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_binaryop = new Pipeline(vkdev); | |||
| pipeline_binaryop->set_optimal_local_size_xyz(); | |||
| pipeline_binaryop->create("binaryop", specializations, 3, 15); | |||
| pipeline_binaryop->create("binaryop", opt, specializations, 3, 15); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_binaryop_pack4 = new Pipeline(vkdev); | |||
| pipeline_binaryop_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_binaryop_pack4->create("binaryop_pack4", specializations, 3, 15); | |||
| pipeline_binaryop_pack4->create("binaryop_pack4", opt, specializations, 3, 15); | |||
| } | |||
| return 0; | |||
| @@ -38,14 +38,14 @@ int Cast_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_cast_fp32_to_fp16 = new Pipeline(vkdev); | |||
| pipeline_cast_fp32_to_fp16->set_optimal_local_size_xyz(); | |||
| pipeline_cast_fp32_to_fp16->create("cast_fp32_to_fp16", specializations, 2, 10); | |||
| pipeline_cast_fp32_to_fp16->create("cast_fp32_to_fp16", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_cast_fp32_to_fp16_pack4 = new Pipeline(vkdev); | |||
| pipeline_cast_fp32_to_fp16_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_cast_fp32_to_fp16_pack4->create("cast_fp32_to_fp16_pack4", specializations, 2, 10); | |||
| pipeline_cast_fp32_to_fp16_pack4->create("cast_fp32_to_fp16_pack4", opt, specializations, 2, 10); | |||
| } | |||
| } | |||
| @@ -55,14 +55,14 @@ int Cast_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_cast_fp16_to_fp32 = new Pipeline(vkdev); | |||
| pipeline_cast_fp16_to_fp32->set_optimal_local_size_xyz(); | |||
| pipeline_cast_fp16_to_fp32->create("cast_fp16_to_fp32", specializations, 2, 10); | |||
| pipeline_cast_fp16_to_fp32->create("cast_fp16_to_fp32", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_cast_fp16_to_fp32_pack4 = new Pipeline(vkdev); | |||
| pipeline_cast_fp16_to_fp32_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_cast_fp16_to_fp32_pack4->create("cast_fp16_to_fp32_pack4", specializations, 2, 10); | |||
| pipeline_cast_fp16_to_fp32_pack4->create("cast_fp16_to_fp32_pack4", opt, specializations, 2, 10); | |||
| } | |||
| } | |||
| @@ -36,14 +36,14 @@ int Clip_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_clip = new Pipeline(vkdev); | |||
| pipeline_clip->set_optimal_local_size_xyz(); | |||
| pipeline_clip->create("clip", specializations, 1, 5); | |||
| pipeline_clip->create("clip", opt, specializations, 1, 5); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_clip_pack4 = new Pipeline(vkdev); | |||
| pipeline_clip_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_clip_pack4->create("clip_pack4", specializations, 1, 5); | |||
| pipeline_clip_pack4->create("clip_pack4", opt, specializations, 1, 5); | |||
| } | |||
| return 0; | |||
| @@ -40,30 +40,30 @@ int Concat_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_concat[0] = new Pipeline(vkdev); | |||
| pipeline_concat[0]->set_optimal_local_size_xyz(); | |||
| pipeline_concat[0]->create("concat", specializations, 2, 11); | |||
| pipeline_concat[0]->create("concat", opt, specializations, 2, 11); | |||
| pipeline_concat[1] = new Pipeline(vkdev); | |||
| pipeline_concat[1]->set_optimal_local_size_xyz(); | |||
| pipeline_concat[1]->create("concat", specializations, 2, 11); | |||
| pipeline_concat[1]->create("concat", opt, specializations, 2, 11); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_concat_pack4[0] = new Pipeline(vkdev); | |||
| pipeline_concat_pack4[0]->set_optimal_local_size_xyz(); | |||
| pipeline_concat_pack4[0]->create("concat_pack4", specializations, 2, 11); | |||
| pipeline_concat_pack4[0]->create("concat_pack4", opt, specializations, 2, 11); | |||
| pipeline_concat_pack4[1] = new Pipeline(vkdev); | |||
| pipeline_concat_pack4[1]->set_optimal_local_size_xyz(); | |||
| pipeline_concat_pack4[1]->create("concat_pack4", specializations, 2, 11); | |||
| pipeline_concat_pack4[1]->create("concat_pack4", opt, specializations, 2, 11); | |||
| } | |||
| // pack4to1 | |||
| { | |||
| pipeline_concat_pack4to1[0] = new Pipeline(vkdev); | |||
| pipeline_concat_pack4to1[0]->set_optimal_local_size_xyz(); | |||
| pipeline_concat_pack4to1[0]->create("concat_pack4to1", specializations, 2, 11); | |||
| pipeline_concat_pack4to1[0]->create("concat_pack4to1", opt, specializations, 2, 11); | |||
| pipeline_concat_pack4to1[1] = new Pipeline(vkdev); | |||
| pipeline_concat_pack4to1[1]->set_optimal_local_size_xyz(); | |||
| pipeline_concat_pack4to1[1]->create("concat_pack4to1", specializations, 2, 11); | |||
| pipeline_concat_pack4to1[1]->create("concat_pack4to1", opt, specializations, 2, 11); | |||
| } | |||
| return 0; | |||
| @@ -84,7 +84,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolution = new Pipeline(vkdev); | |||
| pipeline_convolution->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_convolution->create("convolution", specializations, 4, 10); | |||
| pipeline_convolution->create("convolution", opt, specializations, 4, 10); | |||
| if (kernel_w == 1 && kernel_h == 1 && stride_w == 1 && stride_h == 1 && dilation_w == 1 && dilation_h == 1) | |||
| { | |||
| @@ -97,7 +97,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| specializations[2].f = activation_params.w == 1 ? activation_params[0] : 0.f; | |||
| specializations[3].f = activation_params.w == 2 ? activation_params[1] : 0.f; | |||
| pipeline_convolution_1x1s1d1->create("convolution_1x1s1d1", specializations, 4, 8); | |||
| pipeline_convolution_1x1s1d1->create("convolution_1x1s1d1", opt, specializations, 4, 8); | |||
| } | |||
| } | |||
| @@ -106,7 +106,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolution_pack4 = new Pipeline(vkdev); | |||
| pipeline_convolution_pack4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_convolution_pack4->create("convolution_pack4", specializations, 4, 10); | |||
| pipeline_convolution_pack4->create("convolution_pack4", opt, specializations, 4, 10); | |||
| if (kernel_w == 1 && kernel_h == 1 && stride_w == 1 && stride_h == 1 && dilation_w == 1 && dilation_h == 1) | |||
| { | |||
| @@ -119,7 +119,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| specializations[2].f = activation_params.w == 1 ? activation_params[0] : 0.f; | |||
| specializations[3].f = activation_params.w == 2 ? activation_params[1] : 0.f; | |||
| pipeline_convolution_pack4_1x1s1d1->create("convolution_pack4_1x1s1d1", specializations, 4, 8); | |||
| pipeline_convolution_pack4_1x1s1d1->create("convolution_pack4_1x1s1d1", opt, specializations, 4, 8); | |||
| } | |||
| if (kernel_w == 3 && kernel_h == 3 && stride_w == 1 && stride_h == 1 && dilation_w == 1 && dilation_h == 1) | |||
| @@ -132,7 +132,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| pipeline_convolution_pack4_3x3s1d1_lds_8_8_2 = new Pipeline(vkdev); | |||
| pipeline_convolution_pack4_3x3s1d1_lds_8_8_2->set_local_size_xyz(8, 8, 2); | |||
| pipeline_convolution_pack4_3x3s1d1_lds_8_8_2->create("convolution_pack4_3x3s1d1_lds_8_8_2", specializations, 4, 10); | |||
| pipeline_convolution_pack4_3x3s1d1_lds_8_8_2->create("convolution_pack4_3x3s1d1_lds_8_8_2", opt, specializations, 4, 10); | |||
| if (num_input >= 16 && num_output >= 16) | |||
| { | |||
| @@ -172,15 +172,15 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_transform_input = new Pipeline(vkdev); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_transform_input->set_local_size_xyz(8, 8, 1); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_transform_input->create("convolution_pack4_3x3s1d1_winograd23_transform_input", std::vector<vk_specialization_type>(), 2, 7); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_transform_input->create("convolution_pack4_3x3s1d1_winograd23_transform_input", opt, std::vector<vk_specialization_type>(), 2, 7); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_gemm = new Pipeline(vkdev); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_gemm->set_local_size_xyz(4, 4, 4); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_gemm->create("convolution_pack4_3x3s1d1_winograd23_gemm", std::vector<vk_specialization_type>(), 3, 6); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_gemm->create("convolution_pack4_3x3s1d1_winograd23_gemm", opt, std::vector<vk_specialization_type>(), 3, 6); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_transform_output = new Pipeline(vkdev); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_transform_output->set_local_size_xyz(8, 8, 1); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_transform_output->create("convolution_pack4_3x3s1d1_winograd23_transform_output", specializations, 3, 7); | |||
| pipeline_convolution_pack4_3x3s1d1_winograd23_transform_output->create("convolution_pack4_3x3s1d1_winograd23_transform_output", opt, specializations, 3, 7); | |||
| } | |||
| } | |||
| } | |||
| @@ -190,7 +190,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolution_pack1to4 = new Pipeline(vkdev); | |||
| pipeline_convolution_pack1to4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_convolution_pack1to4->create("convolution_pack1to4", specializations, 4, 10); | |||
| pipeline_convolution_pack1to4->create("convolution_pack1to4", opt, specializations, 4, 10); | |||
| } | |||
| // pack4to1 | |||
| @@ -198,7 +198,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolution_pack4to1 = new Pipeline(vkdev); | |||
| pipeline_convolution_pack4to1->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_convolution_pack4to1->create("convolution_pack4to1", specializations, 4, 10); | |||
| pipeline_convolution_pack4to1->create("convolution_pack4to1", opt, specializations, 4, 10); | |||
| } | |||
| // fc | |||
| @@ -215,7 +215,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_innerproduct = new Pipeline(vkdev); | |||
| pipeline_innerproduct->set_optimal_local_size_xyz(num_output, 1, 1); | |||
| pipeline_innerproduct->create("innerproduct", specializations, 4, 10); | |||
| pipeline_innerproduct->create("innerproduct", opt, specializations, 4, 10); | |||
| } | |||
| // pack4 | |||
| @@ -223,7 +223,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_innerproduct_pack4 = new Pipeline(vkdev); | |||
| pipeline_innerproduct_pack4->set_optimal_local_size_xyz(num_output / 4, 1, 1); | |||
| pipeline_innerproduct_pack4->create("innerproduct_pack4", specializations, 4, 10); | |||
| pipeline_innerproduct_pack4->create("innerproduct_pack4", opt, specializations, 4, 10); | |||
| } | |||
| // pack1to4 | |||
| @@ -231,7 +231,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_innerproduct_pack1to4 = new Pipeline(vkdev); | |||
| pipeline_innerproduct_pack1to4->set_optimal_local_size_xyz(num_output / 4, 1, 1); | |||
| pipeline_innerproduct_pack1to4->create("innerproduct_pack1to4", specializations, 4, 10); | |||
| pipeline_innerproduct_pack1to4->create("innerproduct_pack1to4", opt, specializations, 4, 10); | |||
| } | |||
| // pack4to1 | |||
| @@ -239,7 +239,7 @@ int Convolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_innerproduct_pack4to1 = new Pipeline(vkdev); | |||
| pipeline_innerproduct_pack4to1->set_optimal_local_size_xyz(num_output, 1, 1); | |||
| pipeline_innerproduct_pack4to1->create("innerproduct_pack4to1", specializations, 4, 10); | |||
| pipeline_innerproduct_pack4to1->create("innerproduct_pack4to1", opt, specializations, 4, 10); | |||
| } | |||
| } | |||
| @@ -313,7 +313,7 @@ int Convolution_vulkan::destroy_pipeline(const Option& opt) | |||
| return 0; | |||
| } | |||
| int Convolution_vulkan::upload_model(VkTransfer& cmd) | |||
| int Convolution_vulkan::upload_model(VkTransfer& cmd, const Option& opt) | |||
| { | |||
| const int maxk = kernel_w * kernel_h; | |||
| int num_input = weight_data_size / maxk / num_output; | |||
| @@ -321,7 +321,7 @@ int Convolution_vulkan::upload_model(VkTransfer& cmd) | |||
| // pack1 | |||
| if (num_input % 4 != 0 && num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(weight_data, weight_data_gpu); | |||
| cmd.record_upload(weight_data, weight_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -396,7 +396,7 @@ int Convolution_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4); | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4, opt); | |||
| if (kernel_w == 3 && kernel_h == 3 && stride_w == 1 && stride_h == 1 && dilation_w == 1 && dilation_h == 1 && num_input >= 16 && num_output >= 16) | |||
| { | |||
| @@ -514,7 +514,7 @@ int Convolution_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4_tm, weight_data_gpu_pack4_tm); | |||
| cmd.record_upload(weight_data_pack4_tm, weight_data_gpu_pack4_tm, opt); | |||
| } | |||
| } | |||
| @@ -560,7 +560,7 @@ int Convolution_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack1to4, weight_data_gpu_pack1to4); | |||
| cmd.record_upload(weight_data_pack1to4, weight_data_gpu_pack1to4, opt); | |||
| } | |||
| // pack4to1 | |||
| @@ -601,21 +601,21 @@ int Convolution_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4to1, weight_data_gpu_pack4to1); | |||
| cmd.record_upload(weight_data_pack4to1, weight_data_gpu_pack4to1, opt); | |||
| } | |||
| if (bias_term) | |||
| { | |||
| if (num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(bias_data, bias_data_gpu); | |||
| cmd.record_upload(bias_data, bias_data_gpu, opt); | |||
| } | |||
| if (num_output % 4 == 0) | |||
| { | |||
| Mat bias_data_pack4; | |||
| convert_packing(bias_data, bias_data_pack4, 4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4, opt); | |||
| } | |||
| } | |||
| @@ -753,7 +753,7 @@ int Convolution_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCom | |||
| int out_packing = num_output % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -27,7 +27,7 @@ public: | |||
| virtual int create_pipeline(const Option& opt); | |||
| virtual int destroy_pipeline(const Option& opt); | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt); | |||
| virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const; | |||
| @@ -80,7 +80,7 @@ int ConvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolutiondepthwise = new Pipeline(vkdev); | |||
| pipeline_convolutiondepthwise->set_optimal_local_size_xyz(32, 32, num_output); | |||
| pipeline_convolutiondepthwise->create("convolutiondepthwise", specializations, 4, 10); | |||
| pipeline_convolutiondepthwise->create("convolutiondepthwise", opt, specializations, 4, 10); | |||
| } | |||
| // pack4 | |||
| @@ -88,7 +88,7 @@ int ConvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolutiondepthwise_pack4 = new Pipeline(vkdev); | |||
| pipeline_convolutiondepthwise_pack4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 4)); | |||
| pipeline_convolutiondepthwise_pack4->create("convolutiondepthwise_pack4", specializations, 4, 10); | |||
| pipeline_convolutiondepthwise_pack4->create("convolutiondepthwise_pack4", opt, specializations, 4, 10); | |||
| } | |||
| return 0; | |||
| @@ -103,7 +103,7 @@ int ConvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolutiondepthwise_group = new Pipeline(vkdev); | |||
| pipeline_convolutiondepthwise_group->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_convolutiondepthwise_group->create("convolutiondepthwise_group", specializations, 4, 10); | |||
| pipeline_convolutiondepthwise_group->create("convolutiondepthwise_group", opt, specializations, 4, 10); | |||
| } | |||
| // pack4 | |||
| @@ -111,7 +111,7 @@ int ConvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolutiondepthwise_group_pack4 = new Pipeline(vkdev); | |||
| pipeline_convolutiondepthwise_group_pack4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_convolutiondepthwise_group_pack4->create("convolutiondepthwise_group_pack4", specializations, 4, 10); | |||
| pipeline_convolutiondepthwise_group_pack4->create("convolutiondepthwise_group_pack4", opt, specializations, 4, 10); | |||
| } | |||
| // pack1to4 | |||
| @@ -119,7 +119,7 @@ int ConvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolutiondepthwise_group_pack1to4 = new Pipeline(vkdev); | |||
| pipeline_convolutiondepthwise_group_pack1to4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_convolutiondepthwise_group_pack1to4->create("convolutiondepthwise_group_pack1to4", specializations, 4, 10); | |||
| pipeline_convolutiondepthwise_group_pack1to4->create("convolutiondepthwise_group_pack1to4", opt, specializations, 4, 10); | |||
| } | |||
| // pack4to1 | |||
| @@ -127,7 +127,7 @@ int ConvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_convolutiondepthwise_group_pack4to1 = new Pipeline(vkdev); | |||
| pipeline_convolutiondepthwise_group_pack4to1->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_convolutiondepthwise_group_pack4to1->create("convolutiondepthwise_group_pack4to1", specializations, 4, 10); | |||
| pipeline_convolutiondepthwise_group_pack4to1->create("convolutiondepthwise_group_pack4to1", opt, specializations, 4, 10); | |||
| } | |||
| if (channels % 4 == 0 && channels_g % 4 != 0) | |||
| @@ -203,7 +203,7 @@ int ConvolutionDepthWise_vulkan::destroy_pipeline(const Option& opt) | |||
| return 0; | |||
| } | |||
| int ConvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| int ConvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd, const Option& opt) | |||
| { | |||
| const int maxk = kernel_w * kernel_h; | |||
| int channels = (weight_data_size / group) / maxk / (num_output / group) * group; | |||
| @@ -214,7 +214,7 @@ int ConvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| // pack1 | |||
| if (num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(weight_data, weight_data_gpu); | |||
| cmd.record_upload(weight_data, weight_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -224,21 +224,21 @@ int ConvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| Mat weight_data_r2 = weight_data.reshape(maxk, group); | |||
| convert_packing(weight_data_r2, weight_data_pack4, 4); | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4); | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4, opt); | |||
| } | |||
| if (bias_term) | |||
| { | |||
| if (num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(bias_data, bias_data_gpu); | |||
| cmd.record_upload(bias_data, bias_data_gpu, opt); | |||
| } | |||
| if (num_output % 4 == 0) | |||
| { | |||
| Mat bias_data_pack4; | |||
| convert_packing(bias_data, bias_data_pack4, 4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4, opt); | |||
| } | |||
| } | |||
| @@ -252,7 +252,7 @@ int ConvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| // pack1 | |||
| if (channels_g % 4 != 0 && num_output_g % 4 != 0) | |||
| { | |||
| cmd.record_upload(weight_data, weight_data_gpu); | |||
| cmd.record_upload(weight_data, weight_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -334,7 +334,7 @@ int ConvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4_groups, weight_data_gpu_pack4); | |||
| cmd.record_upload(weight_data_pack4_groups, weight_data_gpu_pack4, opt); | |||
| } | |||
| // pack1to4 | |||
| @@ -386,7 +386,7 @@ int ConvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack1to4_groups, weight_data_gpu_pack1to4); | |||
| cmd.record_upload(weight_data_pack1to4_groups, weight_data_gpu_pack1to4, opt); | |||
| } | |||
| // pack4to1 | |||
| @@ -434,21 +434,21 @@ int ConvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4to1_groups, weight_data_gpu_pack4to1); | |||
| cmd.record_upload(weight_data_pack4to1_groups, weight_data_gpu_pack4to1, opt); | |||
| } | |||
| if (bias_term) | |||
| { | |||
| if (num_output_g % 4 != 0) | |||
| { | |||
| cmd.record_upload(bias_data, bias_data_gpu); | |||
| cmd.record_upload(bias_data, bias_data_gpu, opt); | |||
| } | |||
| if (num_output_g % 4 == 0) | |||
| { | |||
| Mat bias_data_pack4; | |||
| convert_packing(bias_data, bias_data_pack4, 4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4, opt); | |||
| } | |||
| } | |||
| @@ -513,7 +513,7 @@ int ConvolutionDepthWise_vulkan::forward(const VkMat& bottom_blob, VkMat& top_bl | |||
| int out_packing = num_output % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -27,7 +27,7 @@ public: | |||
| virtual int create_pipeline(const Option& opt); | |||
| virtual int destroy_pipeline(const Option& opt); | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt); | |||
| virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const; | |||
| @@ -35,14 +35,14 @@ int Crop_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_crop = new Pipeline(vkdev); | |||
| pipeline_crop->set_optimal_local_size_xyz(); | |||
| pipeline_crop->create("crop", specializations, 2, 13); | |||
| pipeline_crop->create("crop", opt, specializations, 2, 13); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_crop_pack4 = new Pipeline(vkdev); | |||
| pipeline_crop_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_crop_pack4->create("crop_pack4", specializations, 2, 13); | |||
| pipeline_crop_pack4->create("crop_pack4", opt, specializations, 2, 13); | |||
| } | |||
| return 0; | |||
| @@ -98,7 +98,7 @@ int Crop_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& c | |||
| int out_packing = _outc % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -195,7 +195,7 @@ int Crop_vulkan::forward(const std::vector<VkMat>& bottom_blobs, std::vector<VkM | |||
| int out_packing = _outc % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -67,7 +67,7 @@ int Deconvolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolution = new Pipeline(vkdev); | |||
| pipeline_deconvolution->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_deconvolution->create("deconvolution", specializations, 4, 10); | |||
| pipeline_deconvolution->create("deconvolution", opt, specializations, 4, 10); | |||
| } | |||
| // pack4 | |||
| @@ -75,7 +75,7 @@ int Deconvolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolution_pack4 = new Pipeline(vkdev); | |||
| pipeline_deconvolution_pack4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_deconvolution_pack4->create("deconvolution_pack4", specializations, 4, 10); | |||
| pipeline_deconvolution_pack4->create("deconvolution_pack4", opt, specializations, 4, 10); | |||
| } | |||
| // pack1to4 | |||
| @@ -83,7 +83,7 @@ int Deconvolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolution_pack1to4 = new Pipeline(vkdev); | |||
| pipeline_deconvolution_pack1to4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_deconvolution_pack1to4->create("deconvolution_pack1to4", specializations, 4, 10); | |||
| pipeline_deconvolution_pack1to4->create("deconvolution_pack1to4", opt, specializations, 4, 10); | |||
| } | |||
| // pack4to1 | |||
| @@ -91,7 +91,7 @@ int Deconvolution_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolution_pack4to1 = new Pipeline(vkdev); | |||
| pipeline_deconvolution_pack4to1->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_deconvolution_pack4to1->create("deconvolution_pack4to1", specializations, 4, 10); | |||
| pipeline_deconvolution_pack4to1->create("deconvolution_pack4to1", opt, specializations, 4, 10); | |||
| } | |||
| return 0; | |||
| @@ -121,7 +121,7 @@ int Deconvolution_vulkan::destroy_pipeline(const Option& opt) | |||
| return 0; | |||
| } | |||
| int Deconvolution_vulkan::upload_model(VkTransfer& cmd) | |||
| int Deconvolution_vulkan::upload_model(VkTransfer& cmd, const Option& opt) | |||
| { | |||
| const int maxk = kernel_w * kernel_h; | |||
| int num_input = weight_data_size / maxk / num_output; | |||
| @@ -146,7 +146,7 @@ int Deconvolution_vulkan::upload_model(VkTransfer& cmd) | |||
| // pack1 | |||
| if (num_input % 4 != 0 && num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(weight_data_transposed, weight_data_gpu); | |||
| cmd.record_upload(weight_data_transposed, weight_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -221,7 +221,7 @@ int Deconvolution_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4); | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4, opt); | |||
| } | |||
| // pack1to4 | |||
| @@ -266,7 +266,7 @@ int Deconvolution_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack1to4, weight_data_gpu_pack1to4); | |||
| cmd.record_upload(weight_data_pack1to4, weight_data_gpu_pack1to4, opt); | |||
| } | |||
| // pack4to1 | |||
| @@ -307,21 +307,21 @@ int Deconvolution_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4to1, weight_data_gpu_pack4to1); | |||
| cmd.record_upload(weight_data_pack4to1, weight_data_gpu_pack4to1, opt); | |||
| } | |||
| if (bias_term) | |||
| { | |||
| if (num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(bias_data, bias_data_gpu); | |||
| cmd.record_upload(bias_data, bias_data_gpu, opt); | |||
| } | |||
| if (num_output % 4 == 0) | |||
| { | |||
| Mat bias_data_pack4; | |||
| convert_packing(bias_data, bias_data_pack4, 4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4, opt); | |||
| } | |||
| } | |||
| @@ -27,7 +27,7 @@ public: | |||
| virtual int create_pipeline(const Option& opt); | |||
| virtual int destroy_pipeline(const Option& opt); | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt); | |||
| virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const; | |||
| @@ -77,7 +77,7 @@ int DeconvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolutiondepthwise = new Pipeline(vkdev); | |||
| pipeline_deconvolutiondepthwise->set_optimal_local_size_xyz(32, 32, num_output); | |||
| pipeline_deconvolutiondepthwise->create("deconvolutiondepthwise", specializations, 4, 10); | |||
| pipeline_deconvolutiondepthwise->create("deconvolutiondepthwise", opt, specializations, 4, 10); | |||
| } | |||
| // pack4 | |||
| @@ -85,7 +85,7 @@ int DeconvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolutiondepthwise_pack4 = new Pipeline(vkdev); | |||
| pipeline_deconvolutiondepthwise_pack4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 4)); | |||
| pipeline_deconvolutiondepthwise_pack4->create("deconvolutiondepthwise_pack4", specializations, 4, 10); | |||
| pipeline_deconvolutiondepthwise_pack4->create("deconvolutiondepthwise_pack4", opt, specializations, 4, 10); | |||
| } | |||
| return 0; | |||
| @@ -100,7 +100,7 @@ int DeconvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolutiondepthwise_group = new Pipeline(vkdev); | |||
| pipeline_deconvolutiondepthwise_group->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_deconvolutiondepthwise_group->create("deconvolutiondepthwise_group", specializations, 4, 10); | |||
| pipeline_deconvolutiondepthwise_group->create("deconvolutiondepthwise_group", opt, specializations, 4, 10); | |||
| } | |||
| // pack4 | |||
| @@ -108,7 +108,7 @@ int DeconvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolutiondepthwise_group_pack4 = new Pipeline(vkdev); | |||
| pipeline_deconvolutiondepthwise_group_pack4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_deconvolutiondepthwise_group_pack4->create("deconvolutiondepthwise_group_pack4", specializations, 4, 10); | |||
| pipeline_deconvolutiondepthwise_group_pack4->create("deconvolutiondepthwise_group_pack4", opt, specializations, 4, 10); | |||
| } | |||
| // pack1to4 | |||
| @@ -116,7 +116,7 @@ int DeconvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolutiondepthwise_group_pack1to4 = new Pipeline(vkdev); | |||
| pipeline_deconvolutiondepthwise_group_pack1to4->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_deconvolutiondepthwise_group_pack1to4->create("deconvolutiondepthwise_group_pack1to4", specializations, 4, 10); | |||
| pipeline_deconvolutiondepthwise_group_pack1to4->create("deconvolutiondepthwise_group_pack1to4", opt, specializations, 4, 10); | |||
| } | |||
| // pack4to1 | |||
| @@ -124,7 +124,7 @@ int DeconvolutionDepthWise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_deconvolutiondepthwise_group_pack4to1 = new Pipeline(vkdev); | |||
| pipeline_deconvolutiondepthwise_group_pack4to1->set_optimal_local_size_xyz(32, 32, std::max(1, num_output / 8)); | |||
| pipeline_deconvolutiondepthwise_group_pack4to1->create("deconvolutiondepthwise_group_pack4to1", specializations, 4, 10); | |||
| pipeline_deconvolutiondepthwise_group_pack4to1->create("deconvolutiondepthwise_group_pack4to1", opt, specializations, 4, 10); | |||
| } | |||
| if (channels % 4 == 0 && channels_g % 4 != 0) | |||
| @@ -200,7 +200,7 @@ int DeconvolutionDepthWise_vulkan::destroy_pipeline(const Option& opt) | |||
| return 0; | |||
| } | |||
| int DeconvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| int DeconvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd, const Option& opt) | |||
| { | |||
| const int maxk = kernel_w * kernel_h; | |||
| int channels = (weight_data_size / group) / maxk / (num_output / group) * group; | |||
| @@ -228,7 +228,7 @@ int DeconvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| // pack1 | |||
| if (num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(weight_data_transposed, weight_data_gpu); | |||
| cmd.record_upload(weight_data_transposed, weight_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -241,21 +241,21 @@ int DeconvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| convert_packing(weight_data_r2, weight_data_pack4, 4); | |||
| weight_data_pack4 = weight_data_pack4.reshape(maxk * (group/4)); | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4); | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4, opt); | |||
| } | |||
| if (bias_term) | |||
| { | |||
| if (num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(bias_data, bias_data_gpu); | |||
| cmd.record_upload(bias_data, bias_data_gpu, opt); | |||
| } | |||
| if (num_output % 4 == 0) | |||
| { | |||
| Mat bias_data_pack4; | |||
| convert_packing(bias_data, bias_data_pack4, 4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4, opt); | |||
| } | |||
| } | |||
| @@ -269,7 +269,7 @@ int DeconvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| // pack1 | |||
| if (channels_g % 4 != 0 && num_output_g % 4 != 0) | |||
| { | |||
| cmd.record_upload(weight_data_transposed, weight_data_gpu); | |||
| cmd.record_upload(weight_data_transposed, weight_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -351,7 +351,7 @@ int DeconvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4_groups, weight_data_gpu_pack4); | |||
| cmd.record_upload(weight_data_pack4_groups, weight_data_gpu_pack4, opt); | |||
| } | |||
| // pack1to4 | |||
| @@ -403,7 +403,7 @@ int DeconvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack1to4_groups, weight_data_gpu_pack1to4); | |||
| cmd.record_upload(weight_data_pack1to4_groups, weight_data_gpu_pack1to4, opt); | |||
| } | |||
| // pack4to1 | |||
| @@ -451,21 +451,21 @@ int DeconvolutionDepthWise_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4to1_groups, weight_data_gpu_pack4to1); | |||
| cmd.record_upload(weight_data_pack4to1_groups, weight_data_gpu_pack4to1, opt); | |||
| } | |||
| if (bias_term) | |||
| { | |||
| if (num_output_g % 4 != 0) | |||
| { | |||
| cmd.record_upload(bias_data, bias_data_gpu); | |||
| cmd.record_upload(bias_data, bias_data_gpu, opt); | |||
| } | |||
| if (num_output_g % 4 == 0) | |||
| { | |||
| Mat bias_data_pack4; | |||
| convert_packing(bias_data, bias_data_pack4, 4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4, opt); | |||
| } | |||
| } | |||
| @@ -27,7 +27,7 @@ public: | |||
| virtual int create_pipeline(const Option& opt); | |||
| virtual int destroy_pipeline(const Option& opt); | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt); | |||
| virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const; | |||
| @@ -29,19 +29,21 @@ Dropout_vulkan::Dropout_vulkan() | |||
| int Dropout_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_dropout = new Pipeline(vkdev); | |||
| pipeline_dropout->set_optimal_local_size_xyz(); | |||
| std::vector<vk_specialization_type> specializations(1); | |||
| specializations[0].f = scale; | |||
| pipeline_dropout->create("dropout", specializations, 1, 5); | |||
| // pack1 | |||
| { | |||
| pipeline_dropout = new Pipeline(vkdev); | |||
| pipeline_dropout->set_optimal_local_size_xyz(); | |||
| pipeline_dropout->create("dropout", opt, specializations, 1, 5); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_dropout_pack4 = new Pipeline(vkdev); | |||
| pipeline_dropout_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_dropout_pack4->create("dropout_pack4", specializations, 1, 5); | |||
| pipeline_dropout_pack4->create("dropout_pack4", opt, specializations, 1, 5); | |||
| } | |||
| return 0; | |||
| @@ -39,20 +39,20 @@ int Eltwise_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_eltwise[0] = new Pipeline(vkdev); | |||
| pipeline_eltwise[0]->set_optimal_local_size_xyz(); | |||
| pipeline_eltwise[0]->create("eltwise", specializations, 3, 5+2); | |||
| pipeline_eltwise[0]->create("eltwise", opt, specializations, 3, 5+2); | |||
| pipeline_eltwise[1] = new Pipeline(vkdev); | |||
| pipeline_eltwise[1]->set_optimal_local_size_xyz(); | |||
| pipeline_eltwise[1]->create("eltwise", specializations, 3, 5+2); | |||
| pipeline_eltwise[1]->create("eltwise", opt, specializations, 3, 5+2); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_eltwise_pack4[0] = new Pipeline(vkdev); | |||
| pipeline_eltwise_pack4[0]->set_optimal_local_size_xyz(); | |||
| pipeline_eltwise_pack4[0]->create("eltwise_pack4", specializations, 3, 5+2); | |||
| pipeline_eltwise_pack4[0]->create("eltwise_pack4", opt, specializations, 3, 5+2); | |||
| pipeline_eltwise_pack4[1] = new Pipeline(vkdev); | |||
| pipeline_eltwise_pack4[1]->set_optimal_local_size_xyz(); | |||
| pipeline_eltwise_pack4[1]->create("eltwise_pack4", specializations, 3, 5+2); | |||
| pipeline_eltwise_pack4[1]->create("eltwise_pack4", opt, specializations, 3, 5+2); | |||
| } | |||
| return 0; | |||
| @@ -35,21 +35,21 @@ int Flatten_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_flatten = new Pipeline(vkdev); | |||
| pipeline_flatten->set_optimal_local_size_xyz(); | |||
| pipeline_flatten->create("flatten", specializations, 2, 10); | |||
| pipeline_flatten->create("flatten", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_flatten_pack4 = new Pipeline(vkdev); | |||
| pipeline_flatten_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_flatten_pack4->create("flatten_pack4", specializations, 2, 10); | |||
| pipeline_flatten_pack4->create("flatten_pack4", opt, specializations, 2, 10); | |||
| } | |||
| // pack1to4 | |||
| { | |||
| pipeline_flatten_pack1to4 = new Pipeline(vkdev); | |||
| pipeline_flatten_pack1to4->set_optimal_local_size_xyz(); | |||
| pipeline_flatten_pack1to4->create("flatten_pack1to4", specializations, 2, 10); | |||
| pipeline_flatten_pack1to4->create("flatten_pack1to4", opt, specializations, 2, 10); | |||
| } | |||
| return 0; | |||
| @@ -90,7 +90,7 @@ int Flatten_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute | |||
| int out_packing = total % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -59,7 +59,7 @@ int InnerProduct_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_innerproduct = new Pipeline(vkdev); | |||
| pipeline_innerproduct->set_optimal_local_size_xyz(num_output, 1, 1); | |||
| pipeline_innerproduct->create("innerproduct", specializations, 4, 10); | |||
| pipeline_innerproduct->create("innerproduct", opt, specializations, 4, 10); | |||
| } | |||
| // pack4 | |||
| @@ -67,12 +67,12 @@ int InnerProduct_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_innerproduct_pack4 = new Pipeline(vkdev); | |||
| pipeline_innerproduct_pack4->set_optimal_local_size_xyz(num_output / 4, 1, 1); | |||
| pipeline_innerproduct_pack4->create("innerproduct_pack4", specializations, 4, 10); | |||
| pipeline_innerproduct_pack4->create("innerproduct_pack4", opt, specializations, 4, 10); | |||
| { | |||
| pipeline_innerproduct_pack4_lds_64 = new Pipeline(vkdev); | |||
| pipeline_innerproduct_pack4_lds_64->set_local_size_xyz(64, 1, 1); | |||
| pipeline_innerproduct_pack4_lds_64->create("innerproduct_pack4_lds_64", specializations, 4, 10); | |||
| pipeline_innerproduct_pack4_lds_64->create("innerproduct_pack4_lds_64", opt, specializations, 4, 10); | |||
| } | |||
| } | |||
| @@ -81,7 +81,7 @@ int InnerProduct_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_innerproduct_pack1to4 = new Pipeline(vkdev); | |||
| pipeline_innerproduct_pack1to4->set_optimal_local_size_xyz(num_output / 4, 1, 1); | |||
| pipeline_innerproduct_pack1to4->create("innerproduct_pack1to4", specializations, 4, 10); | |||
| pipeline_innerproduct_pack1to4->create("innerproduct_pack1to4", opt, specializations, 4, 10); | |||
| } | |||
| // pack4to1 | |||
| @@ -89,7 +89,7 @@ int InnerProduct_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_innerproduct_pack4to1 = new Pipeline(vkdev); | |||
| pipeline_innerproduct_pack4to1->set_optimal_local_size_xyz(num_output, 1, 1); | |||
| pipeline_innerproduct_pack4to1->create("innerproduct_pack4to1", specializations, 4, 10); | |||
| pipeline_innerproduct_pack4to1->create("innerproduct_pack4to1", opt, specializations, 4, 10); | |||
| } | |||
| return 0; | |||
| @@ -122,14 +122,14 @@ int InnerProduct_vulkan::destroy_pipeline(const Option& opt) | |||
| return 0; | |||
| } | |||
| int InnerProduct_vulkan::upload_model(VkTransfer& cmd) | |||
| int InnerProduct_vulkan::upload_model(VkTransfer& cmd, const Option& opt) | |||
| { | |||
| int num_input = weight_data_size / num_output; | |||
| // pack1 | |||
| if (num_input % 4 != 0 && num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(weight_data, weight_data_gpu); | |||
| cmd.record_upload(weight_data, weight_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -183,7 +183,7 @@ int InnerProduct_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4); | |||
| cmd.record_upload(weight_data_pack4, weight_data_gpu_pack4, opt); | |||
| } | |||
| // pack1to4 | |||
| @@ -218,7 +218,7 @@ int InnerProduct_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack1to4, weight_data_gpu_pack1to4); | |||
| cmd.record_upload(weight_data_pack1to4, weight_data_gpu_pack1to4, opt); | |||
| } | |||
| // pack4to1 | |||
| @@ -251,21 +251,21 @@ int InnerProduct_vulkan::upload_model(VkTransfer& cmd) | |||
| } | |||
| } | |||
| cmd.record_upload(weight_data_pack4to1, weight_data_gpu_pack4to1); | |||
| cmd.record_upload(weight_data_pack4to1, weight_data_gpu_pack4to1, opt); | |||
| } | |||
| if (bias_term) | |||
| { | |||
| if (num_output % 4 != 0) | |||
| { | |||
| cmd.record_upload(bias_data, bias_data_gpu); | |||
| cmd.record_upload(bias_data, bias_data_gpu, opt); | |||
| } | |||
| if (num_output % 4 == 0) | |||
| { | |||
| Mat bias_data_pack4; | |||
| convert_packing(bias_data, bias_data_pack4, 4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4, opt); | |||
| } | |||
| } | |||
| @@ -290,7 +290,7 @@ int InnerProduct_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCo | |||
| int out_packing = num_output % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -27,7 +27,7 @@ public: | |||
| virtual int create_pipeline(const Option& opt); | |||
| virtual int destroy_pipeline(const Option& opt); | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt); | |||
| virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const; | |||
| @@ -43,14 +43,14 @@ int Interp_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_interp = new Pipeline(vkdev); | |||
| pipeline_interp->set_optimal_local_size_xyz(); | |||
| pipeline_interp->create("interp", specializations, 2, 12); | |||
| pipeline_interp->create("interp", opt, specializations, 2, 12); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_interp_pack4 = new Pipeline(vkdev); | |||
| pipeline_interp_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_interp_pack4->create("interp_pack4", specializations, 2, 12); | |||
| pipeline_interp_pack4->create("interp_pack4", opt, specializations, 2, 12); | |||
| } | |||
| } | |||
| @@ -60,24 +60,24 @@ int Interp_vulkan::create_pipeline(const Option& opt) | |||
| pipeline_interp_bicubic_coeffs_x = new Pipeline(vkdev); | |||
| pipeline_interp_bicubic_coeffs_x->set_optimal_local_size_xyz(64, 1, 1); | |||
| pipeline_interp_bicubic_coeffs_x->create("interp_bicubic_coeffs", specializations, 2, 3); | |||
| pipeline_interp_bicubic_coeffs_x->create("interp_bicubic_coeffs", opt, specializations, 2, 3); | |||
| pipeline_interp_bicubic_coeffs_y = new Pipeline(vkdev); | |||
| pipeline_interp_bicubic_coeffs_y->set_optimal_local_size_xyz(64, 1, 1); | |||
| pipeline_interp_bicubic_coeffs_y->create("interp_bicubic_coeffs", specializations, 2, 3); | |||
| pipeline_interp_bicubic_coeffs_y->create("interp_bicubic_coeffs", opt, specializations, 2, 3); | |||
| // pack1 | |||
| { | |||
| pipeline_interp_bicubic = new Pipeline(vkdev); | |||
| pipeline_interp_bicubic->set_optimal_local_size_xyz(); | |||
| pipeline_interp_bicubic->create("interp_bicubic", specializations, 6, 10); | |||
| pipeline_interp_bicubic->create("interp_bicubic", opt, specializations, 6, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_interp_bicubic_pack4 = new Pipeline(vkdev); | |||
| pipeline_interp_bicubic_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_interp_bicubic_pack4->create("interp_bicubic_pack4", specializations, 6, 10); | |||
| pipeline_interp_bicubic_pack4->create("interp_bicubic_pack4", opt, specializations, 6, 10); | |||
| } | |||
| } | |||
| @@ -52,20 +52,20 @@ int LRN_vulkan::create_pipeline(const Option& opt) | |||
| specializations[2].i = local_size - pad - 1; | |||
| } | |||
| pipeline_lrn_square_pad->create("lrn_square_pad", specializations, 2, 10); | |||
| pipeline_lrn_square_pad->create("lrn_square_pad", opt, specializations, 2, 10); | |||
| // pack4 | |||
| if (region_type == 0) | |||
| { | |||
| pipeline_lrn_square_pad_across_channel_pack4 = new Pipeline(vkdev); | |||
| pipeline_lrn_square_pad_across_channel_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_lrn_square_pad_across_channel_pack4->create("lrn_square_pad_across_channel_pack4", specializations, 2, 10); | |||
| pipeline_lrn_square_pad_across_channel_pack4->create("lrn_square_pad_across_channel_pack4", opt, specializations, 2, 10); | |||
| } | |||
| if (region_type == 1) | |||
| { | |||
| pipeline_lrn_square_pad_within_channel_pack4 = new Pipeline(vkdev); | |||
| pipeline_lrn_square_pad_within_channel_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_lrn_square_pad_within_channel_pack4->create("lrn_square_pad_within_channel_pack4", specializations, 2, 10); | |||
| pipeline_lrn_square_pad_within_channel_pack4->create("lrn_square_pad_within_channel_pack4", opt, specializations, 2, 10); | |||
| } | |||
| } | |||
| @@ -80,20 +80,20 @@ int LRN_vulkan::create_pipeline(const Option& opt) | |||
| specializations[3].f = beta; | |||
| specializations[4].f = bias; | |||
| pipeline_lrn_norm->create("lrn_norm", specializations, 2, 10); | |||
| pipeline_lrn_norm->create("lrn_norm", opt, specializations, 2, 10); | |||
| // pack4 | |||
| if (region_type == 0) | |||
| { | |||
| pipeline_lrn_norm_across_channel_pack4 = new Pipeline(vkdev); | |||
| pipeline_lrn_norm_across_channel_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_lrn_norm_across_channel_pack4->create("lrn_norm_across_channel_pack4", specializations, 2, 10); | |||
| pipeline_lrn_norm_across_channel_pack4->create("lrn_norm_across_channel_pack4", opt, specializations, 2, 10); | |||
| } | |||
| if (region_type == 1) | |||
| { | |||
| pipeline_lrn_norm_within_channel_pack4 = new Pipeline(vkdev); | |||
| pipeline_lrn_norm_within_channel_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_lrn_norm_within_channel_pack4->create("lrn_norm_within_channel_pack4", specializations, 2, 10); | |||
| pipeline_lrn_norm_within_channel_pack4->create("lrn_norm_within_channel_pack4", opt, specializations, 2, 10); | |||
| } | |||
| } | |||
| @@ -34,14 +34,14 @@ int Packing_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_packing_1to4 = new Pipeline(vkdev); | |||
| pipeline_packing_1to4->set_optimal_local_size_xyz(); | |||
| pipeline_packing_1to4->create("packing_1to4", specializations, 2, 10); | |||
| pipeline_packing_1to4->create("packing_1to4", opt, specializations, 2, 10); | |||
| } | |||
| if (out_packing == 1) | |||
| { | |||
| pipeline_packing_4to1 = new Pipeline(vkdev); | |||
| pipeline_packing_4to1->set_optimal_local_size_xyz(); | |||
| pipeline_packing_4to1->create("packing_4to1", specializations, 2, 10); | |||
| pipeline_packing_4to1->create("packing_4to1", opt, specializations, 2, 10); | |||
| } | |||
| return 0; | |||
| @@ -96,7 +96,7 @@ int Packing_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute | |||
| if (dims == 1) | |||
| { | |||
| if (vkdev->info.support_fp16_storage && out_packing == 1) | |||
| if (opt.use_fp16_storage && out_packing == 1) | |||
| { | |||
| top_blob = bottom_blob; | |||
| top_blob.w = w * packing; | |||
| @@ -108,7 +108,7 @@ int Packing_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute | |||
| int outw = (w * packing + out_packing - 1) / out_packing; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -123,7 +123,7 @@ int Packing_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute | |||
| { | |||
| int outh = (h * packing + out_packing - 1) / out_packing; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -138,7 +138,7 @@ int Packing_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute | |||
| { | |||
| int outc = (channels * packing + out_packing - 1) / out_packing; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -36,14 +36,14 @@ int Padding_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_padding = new Pipeline(vkdev); | |||
| pipeline_padding->set_optimal_local_size_xyz(); | |||
| pipeline_padding->create("padding", specializations, 2, 12); | |||
| pipeline_padding->create("padding", opt, specializations, 2, 12); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_padding_pack4 = new Pipeline(vkdev); | |||
| pipeline_padding_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_padding_pack4->create("padding_pack4", specializations, 2, 12); | |||
| pipeline_padding_pack4->create("padding_pack4", opt, specializations, 2, 12); | |||
| } | |||
| return 0; | |||
| @@ -35,14 +35,14 @@ int Permute_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_permute = new Pipeline(vkdev); | |||
| pipeline_permute->set_optimal_local_size_xyz(); | |||
| pipeline_permute->create("permute", specializations, 2, 10); | |||
| pipeline_permute->create("permute", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_permute_pack4to1 = new Pipeline(vkdev); | |||
| pipeline_permute_pack4to1->set_optimal_local_size_xyz(); | |||
| pipeline_permute_pack4to1->create("permute_pack4to1", specializations, 2, 10); | |||
| pipeline_permute_pack4to1->create("permute_pack4to1", opt, specializations, 2, 10); | |||
| } | |||
| return 0; | |||
| @@ -72,7 +72,7 @@ int Permute_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute | |||
| int out_packing = 1; | |||
| size_t out_elemsize = elemsize / packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -72,14 +72,14 @@ int Pooling_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_pooling = new Pipeline(vkdev); | |||
| pipeline_pooling->set_optimal_local_size_xyz(); | |||
| pipeline_pooling->create("pooling", specializations, 2, 10); | |||
| pipeline_pooling->create("pooling", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_pooling_pack4 = new Pipeline(vkdev); | |||
| pipeline_pooling_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_pooling_pack4->create("pooling_pack4", specializations, 2, 10); | |||
| pipeline_pooling_pack4->create("pooling_pack4", opt, specializations, 2, 10); | |||
| } | |||
| if (global_pooling) | |||
| @@ -91,14 +91,14 @@ int Pooling_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_pooling_global = new Pipeline(vkdev); | |||
| pipeline_pooling_global->set_optimal_local_size_xyz(256, 1, 1); | |||
| pipeline_pooling_global->create("pooling_global", specializations, 2, 10); | |||
| pipeline_pooling_global->create("pooling_global", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_pooling_global_pack4 = new Pipeline(vkdev); | |||
| pipeline_pooling_global_pack4->set_optimal_local_size_xyz(256, 1, 1); | |||
| pipeline_pooling_global_pack4->create("pooling_global_pack4", specializations, 2, 10); | |||
| pipeline_pooling_global_pack4->create("pooling_global_pack4", opt, specializations, 2, 10); | |||
| } | |||
| } | |||
| @@ -36,7 +36,7 @@ int PReLU_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_prelu = new Pipeline(vkdev); | |||
| pipeline_prelu->set_optimal_local_size_xyz(8, 8, num_slope); | |||
| pipeline_prelu->create("prelu", specializations, 2, 5); | |||
| pipeline_prelu->create("prelu", opt, specializations, 2, 5); | |||
| } | |||
| // pack4 | |||
| @@ -44,7 +44,7 @@ int PReLU_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_prelu_pack4 = new Pipeline(vkdev); | |||
| pipeline_prelu_pack4->set_optimal_local_size_xyz(8, 8, num_slope / 4); | |||
| pipeline_prelu_pack4->create("prelu_pack4", specializations, 2, 5); | |||
| pipeline_prelu_pack4->create("prelu_pack4", opt, specializations, 2, 5); | |||
| } | |||
| return 0; | |||
| @@ -61,18 +61,18 @@ int PReLU_vulkan::destroy_pipeline(const Option& opt) | |||
| return 0; | |||
| } | |||
| int PReLU_vulkan::upload_model(VkTransfer& cmd) | |||
| int PReLU_vulkan::upload_model(VkTransfer& cmd, const Option& opt) | |||
| { | |||
| if (num_slope == 1) | |||
| { | |||
| // dup4 for pack4 | |||
| Mat slope_data4(4); | |||
| slope_data4.fill(slope_data[0]); | |||
| cmd.record_upload(slope_data4, slope_data_gpu); | |||
| cmd.record_upload(slope_data4, slope_data_gpu, opt); | |||
| } | |||
| else | |||
| { | |||
| cmd.record_upload(slope_data, slope_data_gpu); | |||
| cmd.record_upload(slope_data, slope_data_gpu, opt); | |||
| } | |||
| return 0; | |||
| @@ -27,7 +27,7 @@ public: | |||
| virtual int create_pipeline(const Option& opt); | |||
| virtual int destroy_pipeline(const Option& opt); | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt); | |||
| virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const; | |||
| @@ -55,7 +55,7 @@ int PriorBox_vulkan::create_pipeline(const Option& opt) | |||
| pipeline_priorbox = new Pipeline(vkdev); | |||
| pipeline_priorbox->set_optimal_local_size_xyz(); | |||
| pipeline_priorbox->create("priorbox", specializations, 4, 6); | |||
| pipeline_priorbox->create("priorbox", opt, specializations, 4, 6); | |||
| } | |||
| // mxnet style | |||
| @@ -74,7 +74,7 @@ int PriorBox_vulkan::create_pipeline(const Option& opt) | |||
| pipeline_priorbox_mxnet = new Pipeline(vkdev); | |||
| pipeline_priorbox_mxnet->set_optimal_local_size_xyz(); | |||
| pipeline_priorbox_mxnet->create("priorbox_mxnet", specializations, 3, 4); | |||
| pipeline_priorbox_mxnet->create("priorbox_mxnet", opt, specializations, 3, 4); | |||
| } | |||
| return 0; | |||
| @@ -91,14 +91,14 @@ int PriorBox_vulkan::destroy_pipeline(const Option& opt) | |||
| return 0; | |||
| } | |||
| int PriorBox_vulkan::upload_model(VkTransfer& cmd) | |||
| int PriorBox_vulkan::upload_model(VkTransfer& cmd, const Option& opt) | |||
| { | |||
| cmd.record_upload(min_sizes, min_sizes_gpu); | |||
| cmd.record_upload(min_sizes, min_sizes_gpu, opt); | |||
| if (max_sizes.w > 0) | |||
| cmd.record_upload(max_sizes, max_sizes_gpu); | |||
| cmd.record_upload(max_sizes, max_sizes_gpu, opt); | |||
| cmd.record_upload(aspect_ratios, aspect_ratios_gpu); | |||
| cmd.record_upload(aspect_ratios, aspect_ratios_gpu, opt); | |||
| return 0; | |||
| } | |||
| @@ -109,7 +109,7 @@ int PriorBox_vulkan::forward(const std::vector<VkMat>& bottom_blobs, std::vector | |||
| int h = bottom_blobs[0].h; | |||
| size_t elemsize = 4u; | |||
| if (vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_storage) | |||
| { | |||
| elemsize = 2u; | |||
| } | |||
| @@ -27,7 +27,7 @@ public: | |||
| virtual int create_pipeline(const Option& opt); | |||
| virtual int destroy_pipeline(const Option& opt); | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt); | |||
| virtual int forward(const std::vector<VkMat>& bottom_blobs, std::vector<VkMat>& top_blobs, VkCompute& cmd, const Option& opt) const; | |||
| @@ -35,14 +35,14 @@ int ReLU_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_relu = new Pipeline(vkdev); | |||
| pipeline_relu->set_optimal_local_size_xyz(); | |||
| pipeline_relu->create("relu", specializations, 1, 5); | |||
| pipeline_relu->create("relu", opt, specializations, 1, 5); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_relu_pack4 = new Pipeline(vkdev); | |||
| pipeline_relu_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_relu_pack4->create("relu_pack4", specializations, 1, 5); | |||
| pipeline_relu_pack4->create("relu_pack4", opt, specializations, 1, 5); | |||
| } | |||
| return 0; | |||
| @@ -36,21 +36,21 @@ int Reorg_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_reorg = new Pipeline(vkdev); | |||
| pipeline_reorg->set_optimal_local_size_xyz(); | |||
| pipeline_reorg->create("reorg", specializations, 2, 10); | |||
| pipeline_reorg->create("reorg", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_reorg_pack4 = new Pipeline(vkdev); | |||
| pipeline_reorg_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_reorg_pack4->create("reorg_pack4", specializations, 2, 10); | |||
| pipeline_reorg_pack4->create("reorg_pack4", opt, specializations, 2, 10); | |||
| } | |||
| // pack1to4 | |||
| { | |||
| pipeline_reorg_pack1to4 = new Pipeline(vkdev); | |||
| pipeline_reorg_pack1to4->set_optimal_local_size_xyz(); | |||
| pipeline_reorg_pack1to4->create("reorg_pack1to4", specializations, 2, 10); | |||
| pipeline_reorg_pack1to4->create("reorg_pack1to4", opt, specializations, 2, 10); | |||
| } | |||
| return 0; | |||
| @@ -85,7 +85,7 @@ int Reorg_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& | |||
| int out_packing = outc % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -37,28 +37,28 @@ int Reshape_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_reshape = new Pipeline(vkdev); | |||
| pipeline_reshape->set_optimal_local_size_xyz(); | |||
| pipeline_reshape->create("reshape", specializations, 2, 10); | |||
| pipeline_reshape->create("reshape", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_reshape_pack4 = new Pipeline(vkdev); | |||
| pipeline_reshape_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_reshape_pack4->create("reshape_pack4", specializations, 2, 10); | |||
| pipeline_reshape_pack4->create("reshape_pack4", opt, specializations, 2, 10); | |||
| } | |||
| // pack1to4 | |||
| { | |||
| pipeline_reshape_pack1to4 = new Pipeline(vkdev); | |||
| pipeline_reshape_pack1to4->set_optimal_local_size_xyz(); | |||
| pipeline_reshape_pack1to4->create("reshape_pack1to4", specializations, 2, 10); | |||
| pipeline_reshape_pack1to4->create("reshape_pack1to4", opt, specializations, 2, 10); | |||
| } | |||
| // pack4to1 | |||
| { | |||
| pipeline_reshape_pack4to1 = new Pipeline(vkdev); | |||
| pipeline_reshape_pack4to1->set_optimal_local_size_xyz(); | |||
| pipeline_reshape_pack4to1->create("reshape_pack4to1", specializations, 2, 10); | |||
| pipeline_reshape_pack4to1->create("reshape_pack4to1", opt, specializations, 2, 10); | |||
| } | |||
| return 0; | |||
| @@ -105,7 +105,7 @@ int Reshape_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute | |||
| out_packing = _w % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -137,7 +137,7 @@ int Reshape_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute | |||
| out_packing = _h % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -174,7 +174,7 @@ int Reshape_vulkan::forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute | |||
| out_packing = _c % 4 == 0 ? 4 : 1; | |||
| size_t out_elemsize = elemsize / packing * out_packing; | |||
| if (vkdev->info.support_fp16_packed && !vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_packed && !opt.use_fp16_storage) | |||
| { | |||
| if (out_packing == 4) out_elemsize = 4*2u; | |||
| if (out_packing == 1) out_elemsize = 4u; | |||
| @@ -35,13 +35,13 @@ int Scale_vulkan::create_pipeline(const Option& opt) | |||
| pipeline_scale = new Pipeline(vkdev); | |||
| pipeline_scale->set_optimal_local_size_xyz(); | |||
| pipeline_scale->create("scale", specializations, 3, 5); | |||
| pipeline_scale->create("scale", opt, specializations, 3, 5); | |||
| // pack4 | |||
| { | |||
| pipeline_scale_pack4 = new Pipeline(vkdev); | |||
| pipeline_scale_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_scale_pack4->create("scale_pack4", specializations, 3, 5); | |||
| pipeline_scale_pack4->create("scale_pack4", opt, specializations, 3, 5); | |||
| } | |||
| return 0; | |||
| @@ -55,7 +55,7 @@ int Scale_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_scale = new Pipeline(vkdev); | |||
| pipeline_scale->set_optimal_local_size_xyz(8, 8, scale_data_size); | |||
| pipeline_scale->create("scale", specializations, 3, 5); | |||
| pipeline_scale->create("scale", opt, specializations, 3, 5); | |||
| } | |||
| // pack4 | |||
| @@ -63,7 +63,7 @@ int Scale_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_scale_pack4 = new Pipeline(vkdev); | |||
| pipeline_scale_pack4->set_optimal_local_size_xyz(8, 8, scale_data_size / 4); | |||
| pipeline_scale_pack4->create("scale_pack4", specializations, 3, 5); | |||
| pipeline_scale_pack4->create("scale_pack4", opt, specializations, 3, 5); | |||
| } | |||
| return 0; | |||
| @@ -80,7 +80,7 @@ int Scale_vulkan::destroy_pipeline(const Option& opt) | |||
| return 0; | |||
| } | |||
| int Scale_vulkan::upload_model(VkTransfer& cmd) | |||
| int Scale_vulkan::upload_model(VkTransfer& cmd, const Option& opt) | |||
| { | |||
| if (scale_data_size == -233) | |||
| return 0; | |||
| @@ -88,7 +88,7 @@ int Scale_vulkan::upload_model(VkTransfer& cmd) | |||
| // pack1 | |||
| if (scale_data_size % 4 != 0) | |||
| { | |||
| cmd.record_upload(scale_data, scale_data_gpu); | |||
| cmd.record_upload(scale_data, scale_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -96,7 +96,7 @@ int Scale_vulkan::upload_model(VkTransfer& cmd) | |||
| { | |||
| Mat scale_data_pack4; | |||
| convert_packing(scale_data, scale_data_pack4, 4); | |||
| cmd.record_upload(scale_data_pack4, scale_data_gpu_pack4); | |||
| cmd.record_upload(scale_data_pack4, scale_data_gpu_pack4, opt); | |||
| } | |||
| if (bias_term) | |||
| @@ -104,7 +104,7 @@ int Scale_vulkan::upload_model(VkTransfer& cmd) | |||
| // pack1 | |||
| if (scale_data_size % 4 != 0) | |||
| { | |||
| cmd.record_upload(bias_data, bias_data_gpu); | |||
| cmd.record_upload(bias_data, bias_data_gpu, opt); | |||
| } | |||
| // pack4 | |||
| @@ -112,7 +112,7 @@ int Scale_vulkan::upload_model(VkTransfer& cmd) | |||
| { | |||
| Mat bias_data_pack4; | |||
| convert_packing(bias_data, bias_data_pack4, 4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4); | |||
| cmd.record_upload(bias_data_pack4, bias_data_gpu_pack4, opt); | |||
| } | |||
| } | |||
| @@ -27,7 +27,7 @@ public: | |||
| virtual int create_pipeline(const Option& opt); | |||
| virtual int destroy_pipeline(const Option& opt); | |||
| virtual int upload_model(VkTransfer& cmd); | |||
| virtual int upload_model(VkTransfer& cmd, const Option& opt); | |||
| virtual int forward_inplace(std::vector<VkMat>& bottom_top_blobs, VkCompute& cmd, const Option& opt) const; | |||
| virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const; | |||
| @@ -35,14 +35,14 @@ int ShuffleChannel_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_shufflechannel = new Pipeline(vkdev); | |||
| pipeline_shufflechannel->set_optimal_local_size_xyz(); | |||
| pipeline_shufflechannel->create("shufflechannel", specializations, 2, 10); | |||
| pipeline_shufflechannel->create("shufflechannel", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_shufflechannel_pack4 = new Pipeline(vkdev); | |||
| pipeline_shufflechannel_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_shufflechannel_pack4->create("shufflechannel_pack4", specializations, 2, 10); | |||
| pipeline_shufflechannel_pack4->create("shufflechannel_pack4", opt, specializations, 2, 10); | |||
| } | |||
| return 0; | |||
| @@ -35,14 +35,14 @@ int Sigmoid_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_sigmoid = new Pipeline(vkdev); | |||
| pipeline_sigmoid->set_optimal_local_size_xyz(); | |||
| pipeline_sigmoid->create("sigmoid", specializations, 1, 5); | |||
| pipeline_sigmoid->create("sigmoid", opt, specializations, 1, 5); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_sigmoid_pack4 = new Pipeline(vkdev); | |||
| pipeline_sigmoid_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_sigmoid_pack4->create("sigmoid_pack4", specializations, 1, 5); | |||
| pipeline_sigmoid_pack4->create("sigmoid_pack4", opt, specializations, 1, 5); | |||
| } | |||
| return 0; | |||
| @@ -53,10 +53,10 @@ int Softmax_vulkan::create_pipeline(const Option& opt) | |||
| pipeline_softmax_reduce_sum->set_optimal_local_size_xyz(); | |||
| pipeline_softmax_div_sum->set_optimal_local_size_xyz(); | |||
| pipeline_softmax_reduce_max->create("softmax_reduce_max", specializations, 2, 10); | |||
| pipeline_softmax_exp_sub_max->create("softmax_exp_sub_max", specializations, 2, 10); | |||
| pipeline_softmax_reduce_sum->create("softmax_reduce_sum", specializations, 2, 10); | |||
| pipeline_softmax_div_sum->create("softmax_div_sum", specializations, 2, 10); | |||
| pipeline_softmax_reduce_max->create("softmax_reduce_max", opt, specializations, 2, 10); | |||
| pipeline_softmax_exp_sub_max->create("softmax_exp_sub_max", opt, specializations, 2, 10); | |||
| pipeline_softmax_reduce_sum->create("softmax_reduce_sum", opt, specializations, 2, 10); | |||
| pipeline_softmax_div_sum->create("softmax_div_sum", opt, specializations, 2, 10); | |||
| } | |||
| // pack4 | |||
| @@ -71,10 +71,10 @@ int Softmax_vulkan::create_pipeline(const Option& opt) | |||
| pipeline_softmax_reduce_sum_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_softmax_div_sum_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_softmax_reduce_max_pack4->create("softmax_reduce_max_pack4", specializations, 2, 10); | |||
| pipeline_softmax_exp_sub_max_pack4->create("softmax_exp_sub_max_pack4", specializations, 2, 10); | |||
| pipeline_softmax_reduce_sum_pack4->create("softmax_reduce_sum_pack4", specializations, 2, 10); | |||
| pipeline_softmax_div_sum_pack4->create("softmax_div_sum_pack4", specializations, 2, 10); | |||
| pipeline_softmax_reduce_max_pack4->create("softmax_reduce_max_pack4", opt, specializations, 2, 10); | |||
| pipeline_softmax_exp_sub_max_pack4->create("softmax_exp_sub_max_pack4", opt, specializations, 2, 10); | |||
| pipeline_softmax_reduce_sum_pack4->create("softmax_reduce_sum_pack4", opt, specializations, 2, 10); | |||
| pipeline_softmax_div_sum_pack4->create("softmax_div_sum_pack4", opt, specializations, 2, 10); | |||
| } | |||
| return 0; | |||
| @@ -35,14 +35,14 @@ int TanH_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_tanh = new Pipeline(vkdev); | |||
| pipeline_tanh->set_optimal_local_size_xyz(); | |||
| pipeline_tanh->create("tanh", specializations, 1, 5); | |||
| pipeline_tanh->create("tanh", opt, specializations, 1, 5); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_tanh_pack4 = new Pipeline(vkdev); | |||
| pipeline_tanh_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_tanh_pack4->create("tanh_pack4", specializations, 1, 5); | |||
| pipeline_tanh_pack4->create("tanh_pack4", opt, specializations, 1, 5); | |||
| } | |||
| return 0; | |||
| @@ -28,19 +28,21 @@ UnaryOp_vulkan::UnaryOp_vulkan() | |||
| int UnaryOp_vulkan::create_pipeline(const Option& opt) | |||
| { | |||
| pipeline_unaryop = new Pipeline(vkdev); | |||
| pipeline_unaryop->set_optimal_local_size_xyz(); | |||
| std::vector<vk_specialization_type> specializations(1); | |||
| specializations[0].i = op_type; | |||
| pipeline_unaryop->create("unaryop", specializations, 1, 5); | |||
| // pack1 | |||
| { | |||
| pipeline_unaryop = new Pipeline(vkdev); | |||
| pipeline_unaryop->set_optimal_local_size_xyz(); | |||
| pipeline_unaryop->create("unaryop", opt, specializations, 1, 5); | |||
| } | |||
| // pack4 | |||
| { | |||
| pipeline_unaryop_pack4 = new Pipeline(vkdev); | |||
| pipeline_unaryop_pack4->set_optimal_local_size_xyz(); | |||
| pipeline_unaryop_pack4->create("unaryop_pack4", specializations, 1, 5); | |||
| pipeline_unaryop_pack4->create("unaryop_pack4", opt, specializations, 1, 5); | |||
| } | |||
| return 0; | |||
| @@ -150,8 +150,17 @@ int Net::load_param(FILE* fp) | |||
| blobs.resize((size_t)blob_count); | |||
| #if NCNN_VULKAN | |||
| if (opt.use_vulkan_compute && !vkdev) | |||
| vkdev = get_default_gpu_device(); | |||
| if (opt.use_vulkan_compute) | |||
| { | |||
| if (!vkdev) vkdev = get_default_gpu_device(); | |||
| // sanitize use options | |||
| if (!vkdev->info.support_fp16_packed) opt.use_fp16_packed = false; | |||
| if (!vkdev->info.support_fp16_storage) opt.use_fp16_storage = false; | |||
| if (!vkdev->info.support_fp16_arithmetic) opt.use_fp16_arithmetic = false; | |||
| if (!vkdev->info.support_int8_storage) opt.use_int8_storage = false; | |||
| if (!vkdev->info.support_int8_arithmetic) opt.use_int8_arithmetic = false; | |||
| } | |||
| #endif // NCNN_VULKAN | |||
| ParamDict pd; | |||
| @@ -312,8 +321,17 @@ int Net::load_param_mem(const char* _mem) | |||
| blobs.resize(blob_count); | |||
| #if NCNN_VULKAN | |||
| if (opt.use_vulkan_compute && !vkdev) | |||
| vkdev = get_default_gpu_device(); | |||
| if (opt.use_vulkan_compute) | |||
| { | |||
| if (!vkdev) vkdev = get_default_gpu_device(); | |||
| // sanitize use options | |||
| if (!vkdev->info.support_fp16_packed) opt.use_fp16_packed = false; | |||
| if (!vkdev->info.support_fp16_storage) opt.use_fp16_storage = false; | |||
| if (!vkdev->info.support_fp16_arithmetic) opt.use_fp16_arithmetic = false; | |||
| if (!vkdev->info.support_int8_storage) opt.use_int8_storage = false; | |||
| if (!vkdev->info.support_int8_arithmetic) opt.use_int8_arithmetic = false; | |||
| } | |||
| #endif // NCNN_VULKAN | |||
| ParamDict pd; | |||
| @@ -478,8 +496,17 @@ int Net::load_param_bin(FILE* fp) | |||
| blobs.resize(blob_count); | |||
| #if NCNN_VULKAN | |||
| if (opt.use_vulkan_compute && !vkdev) | |||
| vkdev = get_default_gpu_device(); | |||
| if (opt.use_vulkan_compute) | |||
| { | |||
| if (!vkdev) vkdev = get_default_gpu_device(); | |||
| // sanitize use options | |||
| if (!vkdev->info.support_fp16_packed) opt.use_fp16_packed = false; | |||
| if (!vkdev->info.support_fp16_storage) opt.use_fp16_storage = false; | |||
| if (!vkdev->info.support_fp16_arithmetic) opt.use_fp16_arithmetic = false; | |||
| if (!vkdev->info.support_int8_storage) opt.use_int8_storage = false; | |||
| if (!vkdev->info.support_int8_arithmetic) opt.use_int8_arithmetic = false; | |||
| } | |||
| #endif // NCNN_VULKAN | |||
| ParamDict pd; | |||
| @@ -689,8 +716,17 @@ int Net::load_param(const unsigned char* _mem) | |||
| blobs.resize(blob_count); | |||
| #if NCNN_VULKAN | |||
| if (opt.use_vulkan_compute && !vkdev) | |||
| vkdev = get_default_gpu_device(); | |||
| if (opt.use_vulkan_compute) | |||
| { | |||
| if (!vkdev) vkdev = get_default_gpu_device(); | |||
| // sanitize use options | |||
| if (!vkdev->info.support_fp16_packed) opt.use_fp16_packed = false; | |||
| if (!vkdev->info.support_fp16_storage) opt.use_fp16_storage = false; | |||
| if (!vkdev->info.support_fp16_arithmetic) opt.use_fp16_arithmetic = false; | |||
| if (!vkdev->info.support_int8_storage) opt.use_int8_storage = false; | |||
| if (!vkdev->info.support_int8_arithmetic) opt.use_int8_arithmetic = false; | |||
| } | |||
| #endif // NCNN_VULKAN | |||
| ParamDict pd; | |||
| @@ -1028,7 +1064,7 @@ int Net::upload_model() | |||
| { | |||
| if (layers[i]->support_vulkan) | |||
| { | |||
| int uret = layers[i]->upload_model(cmd); | |||
| int uret = layers[i]->upload_model(cmd, opt); | |||
| if (uret != 0) | |||
| { | |||
| fprintf(stderr, "layer upload_model %d failed\n", (int)i); | |||
| @@ -1044,7 +1080,7 @@ int Net::upload_model() | |||
| int Net::create_pipeline() | |||
| { | |||
| if (vkdev->info.support_fp16_packed || vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_storage) | |||
| { | |||
| { | |||
| cast_float32_to_float16 = ncnn::create_layer(ncnn::LayerType::Cast); | |||
| @@ -1375,7 +1411,7 @@ int Net::forward_layer(int layer_index, std::vector<Mat>& blob_mats, std::vector | |||
| // cast to fp16 | |||
| VkMat bottom_blob_unpacked_fp16; | |||
| if (vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_storage) | |||
| { | |||
| cast_float32_to_float16->forward(bottom_blob_unpacked, bottom_blob_unpacked_fp16, cmd, opt); | |||
| } | |||
| @@ -1477,7 +1513,7 @@ int Net::forward_layer(int layer_index, std::vector<Mat>& blob_mats, std::vector | |||
| // cast to fp16 | |||
| VkMat bottom_blob_unpacked_fp16; | |||
| if (vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_storage) | |||
| { | |||
| cast_float32_to_float16->forward(bottom_blob_unpacked, bottom_blob_unpacked_fp16, cmd, opt); | |||
| } | |||
| @@ -1606,7 +1642,7 @@ int Net::forward_layer(int layer_index, std::vector<Mat>& blob_mats, std::vector | |||
| // cast to fp32 | |||
| VkMat bottom_blob_unpacked_fp32; | |||
| if (vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_storage) | |||
| { | |||
| cast_float16_to_float32->forward(bottom_blob_unpacked, bottom_blob_unpacked_fp32, cmd, opt); | |||
| } | |||
| @@ -1741,7 +1777,7 @@ int Net::forward_layer(int layer_index, std::vector<Mat>& blob_mats, std::vector | |||
| packing_pack1->forward(bottom_blob, bottom_blob_unpacked, cmd, opt); | |||
| // cast to fp32 | |||
| if (vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_storage) | |||
| { | |||
| cast_float16_to_float32->forward(bottom_blob_unpacked, bottom_blobs_unpacked_fp32[i], cmd, opt); | |||
| } | |||
| @@ -1894,16 +1930,6 @@ void Extractor::set_num_threads(int num_threads) | |||
| opt.num_threads = num_threads; | |||
| } | |||
| void Extractor::set_blob_allocator(Allocator* allocator) | |||
| { | |||
| opt.blob_allocator = allocator; | |||
| } | |||
| void Extractor::set_workspace_allocator(Allocator* allocator) | |||
| { | |||
| opt.workspace_allocator = allocator; | |||
| } | |||
| #if NCNN_VULKAN | |||
| void Extractor::set_vulkan_compute(bool enable) | |||
| { | |||
| @@ -1916,21 +1942,6 @@ void Extractor::set_vulkan_compute(bool enable) | |||
| fprintf(stderr, "set_vulkan_compute failed, network use_vulkan_compute disabled\n"); | |||
| } | |||
| } | |||
| void Extractor::set_blob_vkallocator(VkAllocator* allocator) | |||
| { | |||
| opt.blob_vkallocator = allocator; | |||
| } | |||
| void Extractor::set_workspace_vkallocator(VkAllocator* allocator) | |||
| { | |||
| opt.workspace_vkallocator = allocator; | |||
| } | |||
| void Extractor::set_staging_vkallocator(VkAllocator* allocator) | |||
| { | |||
| opt.staging_vkallocator = allocator; | |||
| } | |||
| #endif // NCNN_VULKAN | |||
| #if NCNN_STRING | |||
| @@ -1993,7 +2004,7 @@ int Extractor::extract(int blob_index, Mat& feat) | |||
| // cast to fp32 | |||
| VkMat feat_gpu_unpacked_fp32; | |||
| if (net->vkdev->info.support_fp16_packed || net->vkdev->info.support_fp16_storage) | |||
| if (opt.use_fp16_storage) | |||
| { | |||
| net->cast_float16_to_float32->forward(feat_gpu_unpacked, feat_gpu_unpacked_fp32, cmd, opt); | |||
| } | |||
| @@ -154,20 +154,8 @@ public: | |||
| // default count is system depended | |||
| void set_num_threads(int num_threads); | |||
| // set blob memory allocator | |||
| void set_blob_allocator(Allocator* allocator); | |||
| // set workspace memory allocator | |||
| void set_workspace_allocator(Allocator* allocator); | |||
| #if NCNN_VULKAN | |||
| void set_vulkan_compute(bool enable); | |||
| void set_blob_vkallocator(VkAllocator* allocator); | |||
| void set_workspace_vkallocator(VkAllocator* allocator); | |||
| void set_staging_vkallocator(VkAllocator* allocator); | |||
| #endif // NCNN_VULKAN | |||
| #if NCNN_STRING | |||
| @@ -16,8 +16,9 @@ | |||
| #include <stdio.h> | |||
| #include <math.h> | |||
| #include <algorithm> | |||
| #include "mat.h" | |||
| #include <string> | |||
| #include "mat.h" | |||
| #include "option.h" | |||
| namespace ncnn { | |||
| @@ -66,19 +67,19 @@ int Pipeline::create(VkShaderModule shader_module, const char* entry_name, const | |||
| return 0; | |||
| } | |||
| int Pipeline::create(const char* _name, const std::vector<vk_specialization_type>& specializations, int binding_count, int push_constant_count) | |||
| int Pipeline::create(const char* _name, const Option& opt, const std::vector<vk_specialization_type>& specializations, int binding_count, int push_constant_count) | |||
| { | |||
| std::string name = _name; | |||
| if (vkdev->info.support_fp16_arithmetic) | |||
| if (opt.use_fp16_arithmetic) | |||
| { | |||
| name += "_fp16a"; | |||
| } | |||
| else if (vkdev->info.support_fp16_storage) | |||
| else if (opt.use_fp16_storage) | |||
| { | |||
| name += "_fp16s"; | |||
| } | |||
| else if (vkdev->info.support_fp16_packed) | |||
| else if (opt.use_fp16_packed) | |||
| { | |||
| name += "_fp16p"; | |||
| } | |||
| @@ -25,6 +25,7 @@ | |||
| namespace ncnn { | |||
| #if NCNN_VULKAN | |||
| class Option; | |||
| class Pipeline | |||
| { | |||
| public: | |||
| @@ -39,7 +40,7 @@ public: | |||
| const std::vector<vk_specialization_type>& specializations, int binding_count, int push_constant_count); | |||
| int create(VkShaderModule shader_module, const char* entry_name, | |||
| const std::vector<vk_specialization_type>& specializations, int binding_count, int push_constant_count); | |||
| int create(const char* name, const std::vector<vk_specialization_type>& specializations, | |||
| int create(const char* name, const Option& opt, const std::vector<vk_specialization_type>& specializations, | |||
| int binding_count, int push_constant_count); | |||
| void destroy(); | |||