| 64 | } |
| 65 | |
| 66 | bool update_cryption_key(const Args& args) { |
| 67 | std::string network_path = args.model_path; |
| 68 | std::string input_path = args.input_path; |
| 69 | |
| 70 | //! update the decryption method key |
| 71 | std::vector<uint8_t> key(32, 0); |
| 72 | for (size_t i = 0; i < 32; i++) { |
| 73 | key[i] = 31 - i; |
| 74 | } |
| 75 | update_decryption_or_key("AES_default", nullptr, key); |
| 76 | |
| 77 | lite::Config config; |
| 78 | config.bare_model_cryption_name = "AES_default"; |
| 79 | //! create and load the network |
| 80 | std::shared_ptr<Network> network = std::make_shared<Network>(config); |
| 81 | network->load_model(network_path); |
| 82 | |
| 83 | //! set input data to input tensor |
| 84 | std::shared_ptr<Tensor> input_tensor = network->get_input_tensor(0); |
| 85 | auto layout = input_tensor->get_layout(); |
| 86 | |
| 87 | auto src_tensor = parse_npy(input_path); |
| 88 | void* src = src_tensor->get_memory_ptr(); |
| 89 | input_tensor->reset(src, layout); |
| 90 | |
| 91 | //! forward |
| 92 | network->forward(); |
| 93 | network->wait(); |
| 94 | |
| 95 | //! get the output data or read tensor set in network_in |
| 96 | std::shared_ptr<Tensor> output_tensor = network->get_output_tensor(0); |
| 97 | void* out_data = output_tensor->get_memory_ptr(); |
| 98 | size_t out_length = output_tensor->get_tensor_total_size_in_byte() / |
| 99 | output_tensor->get_layout().get_elem_size(); |
| 100 | float max = -1.0f; |
| 101 | float sum = 0.0f; |
| 102 | for (size_t i = 0; i < out_length; i++) { |
| 103 | float data = static_cast<float*>(out_data)[i]; |
| 104 | sum += data; |
| 105 | if (max < data) |
| 106 | max = data; |
| 107 | } |
| 108 | printf("max=%e, sum=%e\n", max, sum); |
| 109 | return true; |
| 110 | } |
| 111 | } // namespace |
| 112 | |
| 113 | REGIST_EXAMPLE("register_cryption_method", register_cryption_method); |
nothing calls this directly
no test coverage detected