Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhjh committed Feb 13, 2023
1 parent bf61f84 commit 45b070e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
46 changes: 24 additions & 22 deletions fastdeploy/runtime/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,32 @@ bool AutoSelectBackend(RuntimeOption& option) {

bool Runtime::Init(const RuntimeOption& _option) {
option = _option;
// decrypt encrypted model
if ("" != option.encryption_key_) {
#ifdef ENABLE_ENCRYPTION
if (option.model_from_memory_) {
option.model_file = Decrypt(option.model_file, option.encryption_key_);
if (!(option.params_file.empty())) {
option.params_file = Decrypt(option.params_file, option.encryption_key_);
}
} else {
std::string model_buffer = "";
FDASSERT(ReadBinaryFromFile(option.model_file, &model_buffer),
"Fail to read binary from model file");
option.model_file = Decrypt(model_buffer, option.encryption_key_);
if (!(option.params_file.empty())) {
std::string params_buffer = "";
FDASSERT(ReadBinaryFromFile(option.params_file, &params_buffer),
"Fail to read binary from parameter file");
option.params_file = Decrypt(params_buffer, option.encryption_key_);
}
option.model_from_memory_ = true;
#ifdef ENABLE_ENCRYPTION
if (option.model_from_memory_) {
option.model_file = Decrypt(option.model_file, option.encryption_key_);
if (!(option.params_file.empty())) {
option.params_file =
Decrypt(option.params_file, option.encryption_key_);
}
#else
FDERROR << "The FastDeploy didn't compile with encryption function."
<< std::endl;
#endif
} else {
std::string model_buffer = "";
FDASSERT(ReadBinaryFromFile(option.model_file, &model_buffer),
"Fail to read binary from model file");
option.model_file = Decrypt(model_buffer, option.encryption_key_);
if (!(option.params_file.empty())) {
std::string params_buffer = "";
FDASSERT(ReadBinaryFromFile(option.params_file, &params_buffer),
"Fail to read binary from parameter file");
option.params_file = Decrypt(params_buffer, option.encryption_key_);
}
option.model_from_memory_ = true;
}
#else
FDERROR << "The FastDeploy didn't compile with encryption function."
<< std::endl;
#endif
}
// Choose default backend by model format and device if backend is not
// specified
Expand Down
4 changes: 2 additions & 2 deletions fastdeploy/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "fastdeploy/runtime/runtime_option.h"
#include "fastdeploy/utils/perf.h"
#ifdef ENABLE_ENCRYPTION
#include "fastdeploy/encryption/include/decrypt.h"
#include "fastdeploy/encryption/include/decrypt.h"
#endif

/** \brief All C++ FastDeploy APIs are defined inside this namespace
Expand Down Expand Up @@ -102,7 +102,7 @@ struct FASTDEPLOY_DECL Runtime {
*/
double GetProfileTime() {
return backend_->benchmark_result_.time_of_runtime;
}
}

private:
void CreateOrtBackend();
Expand Down
12 changes: 6 additions & 6 deletions fastdeploy/runtime/runtime_option.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ void RuntimeOption::SetModelBuffer(const std::string& model_buffer,
}

void RuntimeOption::SetEncryptionKey(const std::string& encryption_key) {
#ifdef ENABLE_ENCRYPTION
encryption_key_ = encryption_key;
#else
FDERROR << "The FastDeploy didn't compile with encryption function."
<< std::endl;
#endif
#ifdef ENABLE_ENCRYPTION
encryption_key_ = encryption_key;
#else
FDERROR << "The FastDeploy didn't compile with encryption function."
<< std::endl;
#endif
}

void RuntimeOption::UseGpu(int gpu_id) {
Expand Down
2 changes: 1 addition & 1 deletion fastdeploy/runtime/runtime_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct FASTDEPLOY_DECL RuntimeOption {
// *** The belowing api are deprecated, will be removed in v1.2.0
// *** Do not use it anymore

void SetPaddleMKLDNN(bool pd_mkldnn = true);
void SetPaddleMKLDNN(bool pd_mkldnn = true);
void EnablePaddleToTrt();
void DeletePaddleBackendPass(const std::string& delete_pass_name);
void EnablePaddleLogInfo();
Expand Down
16 changes: 9 additions & 7 deletions python/fastdeploy/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ def set_model_buffer(self,
return self._option.set_model_buffer(model_buffer, params_buffer,
model_format)

def set_encryption_key(self,
encryption_key):
def set_encryption_key(self, encryption_key):
"""When loading encrypted model, encryption_key is required to decrypte model
:param encryption_key: (str)The key for decrypting model
"""
Expand Down Expand Up @@ -590,10 +589,12 @@ def set_ipu_config(self,
replica_num=1,
available_memory_proportion=1.0,
enable_half_partial=False):
logging.warning("`RuntimeOption.set_ipu_config` will be deprecated in v1.2.0, please use `RuntimeOption.paddle_infer_option.set_ipu_config()` instead.")
self._option.paddle_infer_option.set_ipu_config(enable_fp16, replica_num,
available_memory_proportion,
enable_half_partial)
logging.warning(
"`RuntimeOption.set_ipu_config` will be deprecated in v1.2.0, please use `RuntimeOption.paddle_infer_option.set_ipu_config()` instead."
)
self._option.paddle_infer_option.set_ipu_config(
enable_fp16, replica_num, available_memory_proportion,
enable_half_partial)

@property
def poros_option(self):
Expand Down Expand Up @@ -664,7 +665,8 @@ def __repr__(self):
continue
if hasattr(getattr(self._option, attr), "__call__"):
continue
message += " {} : {}\t\n".format(attr, getattr(self._option, attr))
message += " {} : {}\t\n".format(attr,
getattr(self._option, attr))
message.strip("\n")
message += ")"
return message

0 comments on commit 45b070e

Please sign in to comment.