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 15import pytest 16 17import ncnn 18 19 20def test_option(): 21 allocator = ncnn.PoolAllocator() 22 23 opt = ncnn.Option() 24 25 opt.lightmode = True 26 assert opt.lightmode == True 27 opt.lightmode = False 28 assert opt.lightmode == False 29 30 assert opt.num_threads == ncnn.get_cpu_count() 31 opt.num_threads = 1 32 assert opt.num_threads == 1 33 34 assert opt.blob_allocator is None 35 opt.blob_allocator = allocator 36 assert opt.blob_allocator == allocator 37 38 assert opt.workspace_allocator is None 39 opt.workspace_allocator = allocator 40 assert opt.workspace_allocator == allocator 41 42 assert opt.openmp_blocktime == 20 43 opt.openmp_blocktime = 40 44 assert opt.openmp_blocktime == 40 45 46 opt.use_winograd_convolution = True 47 assert opt.use_winograd_convolution == True 48 opt.use_winograd_convolution = False 49 assert opt.use_winograd_convolution == False 50 51 opt.use_sgemm_convolution = True 52 assert opt.use_sgemm_convolution == True 53 opt.use_sgemm_convolution = False 54 assert opt.use_sgemm_convolution == False 55 56 opt.use_int8_inference = True 57 assert opt.use_int8_inference == True 58 opt.use_int8_inference = False 59 assert opt.use_int8_inference == False 60 61 opt.use_vulkan_compute = True 62 assert opt.use_vulkan_compute == True 63 opt.use_vulkan_compute = False 64 assert opt.use_vulkan_compute == False 65 66 opt.use_bf16_storage = True 67 assert opt.use_bf16_storage == True 68 opt.use_bf16_storage = False 69 assert opt.use_bf16_storage == False 70 71 opt.use_fp16_packed = True 72 assert opt.use_fp16_packed == True 73 opt.use_fp16_packed = False 74 assert opt.use_fp16_packed == False 75 76 opt.use_fp16_storage = True 77 assert opt.use_fp16_storage == True 78 opt.use_fp16_storage = False 79 assert opt.use_fp16_storage == False 80 81 opt.use_fp16_arithmetic = True 82 assert opt.use_fp16_arithmetic == True 83 opt.use_fp16_arithmetic = False 84 assert opt.use_fp16_arithmetic == False 85 86 opt.use_int8_packed = True 87 assert opt.use_int8_packed == True 88 opt.use_int8_packed = False 89 assert opt.use_int8_packed == False 90 91 opt.use_int8_storage = True 92 assert opt.use_int8_storage == True 93 opt.use_int8_storage = False 94 assert opt.use_int8_storage == False 95 96 opt.use_int8_arithmetic = True 97 assert opt.use_int8_arithmetic == True 98 opt.use_int8_arithmetic = False 99 assert opt.use_int8_arithmetic == False 100 101 opt.use_packing_layout = True 102 assert opt.use_packing_layout == True 103 opt.use_packing_layout = False 104 assert opt.use_packing_layout == False 105 106 opt.use_shader_pack8 = True 107 assert opt.use_shader_pack8 == True 108 opt.use_shader_pack8 = False 109 assert opt.use_shader_pack8 == False 110 111 opt.use_subgroup_basic = True 112 assert opt.use_subgroup_basic == True 113 opt.use_subgroup_basic = False 114 assert opt.use_subgroup_basic == False 115 116 opt.use_subgroup_vote = True 117 assert opt.use_subgroup_vote == True 118 opt.use_subgroup_vote = False 119 assert opt.use_subgroup_vote == False 120 121 opt.use_subgroup_ballot = True 122 assert opt.use_subgroup_ballot == True 123 opt.use_subgroup_ballot = False 124 assert opt.use_subgroup_ballot == False 125 126 opt.use_subgroup_shuffle = True 127 assert opt.use_subgroup_shuffle == True 128 opt.use_subgroup_shuffle = False 129 assert opt.use_subgroup_shuffle == False 130 131 opt.use_image_storage = True 132 assert opt.use_image_storage == True 133 opt.use_image_storage = False 134 assert opt.use_image_storage == False 135 136 opt.use_tensor_storage = True 137 assert opt.use_tensor_storage == True 138 opt.use_tensor_storage = False 139 assert opt.use_tensor_storage == False 140 141 opt.use_weight_fp16_storage = True 142 assert opt.use_weight_fp16_storage == True 143 opt.use_weight_fp16_storage = False 144 assert opt.use_weight_fp16_storage == False 145