diff --git a/mace/core/file_storage.cc b/mace/core/file_storage.cc new file mode 100644 index 0000000000000000000000000000000000000000..e7916b512048cf87dfc8d0acafeb3e289d16e484 --- /dev/null +++ b/mace/core/file_storage.cc @@ -0,0 +1,108 @@ +// +// Copyright (c) 2017 XiaoMi All rights reserved. +// + +#include "mace/core/file_storage.h" + +#include +#include +#include + +#include "mace/utils/logging.h" + +namespace mace { + +class FileStorageFactory::Impl { + public: + explicit Impl(const std::string &path); + + std::unique_ptr CreateStorage(const std::string &name); + + private: + std::string path_; +}; + +FileStorageFactory::Impl::Impl(const std::string &path): path_(path) {} +std::unique_ptr FileStorageFactory::Impl::CreateStorage( + const std::string &name) { + return std::move(std::unique_ptr( + new FileStorage(path_ + "/" + name))); +} + +FileStorageFactory::FileStorageFactory(const std::string &path): + impl_(new FileStorageFactory::Impl(path)) {} + +FileStorageFactory::~FileStorageFactory() = default; + +std::unique_ptr FileStorageFactory::CreateStorage( + const std::string &name) { + return impl_->CreateStorage(name); +} + +FileStorage::FileStorage(const std::string &file_path): + file_path_(file_path) {} + +void FileStorage::Load() { + std::ifstream ifs(file_path_, std::ios::binary | std::ios::in); + if (ifs.is_open()) { + int64_t data_size = 0; + ifs.read(reinterpret_cast(&data_size), sizeof(data_size)); + while (data_size--) { + int32_t key_size = 0; + ifs.read(reinterpret_cast(&key_size), sizeof(key_size)); + std::string key(key_size, ' '); + ifs.read(&key[0], key_size); + + int32_t value_size = 0; + ifs.read(reinterpret_cast(&value_size), + sizeof(value_size)); + + std::vector value(value_size); + ifs.read(reinterpret_cast(value.data()), + value_size); + data_.emplace(key, value); + } + ifs.close(); + } else { + LOG(INFO) << "No file to Read."; + } +} + +bool FileStorage::Insert(const std::string &key, + const std::vector &value) { + data_.emplace(key, value); + return true; +} + +std::vector *FileStorage::Find(const std::string &key) { + auto iter = data_.find(key); + if (iter == data_.end()) return nullptr; + + return &(iter->second); +} + +void FileStorage::Flush() { + std::ofstream ofs(file_path_, + std::ios::binary | std::ios::out); + if (ofs.is_open()) { + int64_t data_size = data_.size(); + ofs.write(reinterpret_cast(&data_size), + sizeof(data_size)); + for (auto &kv : data_) { + int32_t key_size = static_cast(kv.first.size()); + ofs.write(reinterpret_cast(&key_size), sizeof(key_size)); + ofs.write(kv.first.c_str(), key_size); + + int32_t value_size = static_cast(kv.second.size()); + ofs.write(reinterpret_cast(&value_size), + sizeof(value_size)); + ofs.write(reinterpret_cast(kv.second.data()), + value_size); + } + ofs.close(); + } else { + LOG(WARNING) << "Write failed, please check directory exists"; + } +} + +}; // namespace mace diff --git a/mace/core/file_storage.h b/mace/core/file_storage.h new file mode 100644 index 0000000000000000000000000000000000000000..b1c90b50351f559a0d0a8315256b39fa1eeb6bca --- /dev/null +++ b/mace/core/file_storage.h @@ -0,0 +1,34 @@ +// +// Copyright (c) 2017 XiaoMi All rights reserved. +// + +#ifndef MACE_CORE_FILE_STORAGE_H_ +#define MACE_CORE_FILE_STORAGE_H_ + +#include +#include +#include + +#include "mace/public/mace_runtime.h" + +namespace mace { + +class FileStorage : public KVStorage { + public: + explicit FileStorage(const std::string &file_path); + + public: + void Load() override; + bool Insert(const std::string &key, + const std::vector &value) override; + std::vector *Find(const std::string &key) override; + void Flush() override; + + private: + std::string file_path_; + std::map> data_; +}; + +} // namespace mace + +#endif // MACE_CORE_FILE_STORAGE_H_ diff --git a/mace/core/file_storage_engine.cc b/mace/core/file_storage_engine.cc deleted file mode 100644 index a3cd12f180875d885a49f7057ebe3e195e19c545..0000000000000000000000000000000000000000 --- a/mace/core/file_storage_engine.cc +++ /dev/null @@ -1,74 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#include "mace/core/file_storage_engine.h" - -#include - -#include "mace/utils/logging.h" - -namespace mace { - -std::string FileStorageEngine::kStoragePath // NOLINT(runtime/string) - = "/data/local/tmp"; - -FileStorageEngine::FileStorageEngine(const std::string &file_name): - file_name_(file_name) {} - -void FileStorageEngine::Write( - const std::map> &data) { - const std::string file_path = kStoragePath + "/" + file_name_; - - std::ofstream ofs(file_path, - std::ios::binary | std::ios::out); - if (ofs.is_open()) { - int64_t data_size = data.size(); - ofs.write(reinterpret_cast(&data_size), - sizeof(data_size)); - for (auto &kv : data) { - int32_t key_size = static_cast(kv.first.size()); - ofs.write(reinterpret_cast(&key_size), sizeof(key_size)); - ofs.write(kv.first.c_str(), key_size); - - int32_t value_size = static_cast(kv.second.size()); - ofs.write(reinterpret_cast(&value_size), - sizeof(value_size)); - ofs.write(reinterpret_cast(kv.second.data()), - value_size); - } - ofs.close(); - } else { - LOG(WARNING) << "Write failed, please check directory exists"; - } -} - -void FileStorageEngine::Read( - std::map> *data) { - const std::string file_path = kStoragePath + "/" + file_name_; - std::ifstream ifs(file_path, std::ios::binary | std::ios::in); - if (ifs.is_open()) { - int64_t data_size = 0; - ifs.read(reinterpret_cast(&data_size), sizeof(data_size)); - while (data_size--) { - int32_t key_size = 0; - ifs.read(reinterpret_cast(&key_size), sizeof(key_size)); - std::string key(key_size, ' '); - ifs.read(&key[0], key_size); - - int32_t value_size = 0; - ifs.read(reinterpret_cast(&value_size), - sizeof(value_size)); - - std::vector program_binary(value_size); - ifs.read(reinterpret_cast(program_binary.data()), - value_size); - data->emplace(key, program_binary); - } - ifs.close(); - } else { - LOG(INFO) << "No file to Read."; - } -} - -}; // namespace mace diff --git a/mace/core/file_storage_engine.h b/mace/core/file_storage_engine.h deleted file mode 100644 index 9ce742a4d2cdeabb79c04549a3fd8a8969f1b715..0000000000000000000000000000000000000000 --- a/mace/core/file_storage_engine.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#ifndef MACE_CORE_FILE_STORAGE_ENGINE_H_ -#define MACE_CORE_FILE_STORAGE_ENGINE_H_ - -#include -#include -#include - -#include "mace/public/mace_runtime.h" - -namespace mace { - -class FileStorageEngine : public KVStorageEngine { - public: - explicit FileStorageEngine(const std::string &file_name); - public: - void Write( - const std::map> &data) override; - void Read( - std::map> *data) override; - private: - std::string file_name_; - - public: - static std::string kStoragePath; -}; - -} // namespace mace - -#endif // MACE_CORE_FILE_STORAGE_ENGINE_H_ diff --git a/mace/core/mace.cc b/mace/core/mace.cc index f5b73a3933ac93de1161c683e5daf0985386e392..484c9472af8e9e12124c78b054d539584e4d2801 100644 --- a/mace/core/mace.cc +++ b/mace/core/mace.cc @@ -4,7 +4,7 @@ #include -#include "mace/core/file_storage_engine.h" +#include "mace/core/file_storage.h" #include "mace/core/net.h" #include "mace/core/runtime/hexagon/hexagon_control_wrapper.h" #include "mace/core/runtime/opencl/opencl_runtime.h" @@ -69,8 +69,7 @@ class MaceEngine::Impl { explicit Impl(const NetDef *net_def, DeviceType device_type, const std::vector &input_nodes, - const std::vector &output_nodes, - const std::string &internal_storage_path); + const std::vector &output_nodes); ~Impl(); MaceStatus Run(const std::map &inputs, @@ -90,8 +89,7 @@ class MaceEngine::Impl { MaceEngine::Impl::Impl(const NetDef *net_def, DeviceType device_type, const std::vector &input_nodes, - const std::vector &output_nodes, - const std::string &internal_storage_path) + const std::vector &output_nodes) : op_registry_(new OperatorRegistry()), device_type_(device_type), ws_(new Workspace()), @@ -99,7 +97,6 @@ MaceEngine::Impl::Impl(const NetDef *net_def, hexagon_controller_(nullptr) { LOG(INFO) << "MACE version: " << MaceVersion(); // Set storage path for internal usage - FileStorageEngine::kStoragePath = internal_storage_path; for (auto input_name : input_nodes) { ws_->CreateTensor(MakeString("mace_input_node_", input_name, ":0"), GetDeviceAllocator(device_type_), DT_FLOAT); @@ -206,11 +203,9 @@ MaceStatus MaceEngine::Impl::Run( MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type, const std::vector &input_nodes, - const std::vector &output_nodes, - const std::string &internal_storage_path) { + const std::vector &output_nodes) { impl_ = std::unique_ptr( - new MaceEngine::Impl(net_def, device_type, input_nodes, - output_nodes, internal_storage_path)); + new MaceEngine::Impl(net_def, device_type, input_nodes, output_nodes)); } MaceEngine::~MaceEngine() = default; diff --git a/mace/core/mace_runtime.cc b/mace/core/mace_runtime.cc index fb5110bce17472fc21aadf357b8257f64dc8807f..5f94195370990480c0003836cbde8d2a529c70c3 100644 --- a/mace/core/mace_runtime.cc +++ b/mace/core/mace_runtime.cc @@ -8,6 +8,8 @@ namespace mace { +std::shared_ptr kStorageFactory = nullptr; + void ConfigOpenCLRuntime(GPUPerfHint gpu_perf_hint, GPUPriorityHint gpu_priority_hint) { VLOG(1) << "Set GPU configurations, gpu_perf_hint: " << gpu_perf_hint @@ -15,9 +17,9 @@ void ConfigOpenCLRuntime(GPUPerfHint gpu_perf_hint, OpenCLRuntime::Configure(gpu_perf_hint, gpu_priority_hint); } -void ConfigKVStorageEngine(std::shared_ptr storage_engine) { +void ConfigKVStorageFactory(std::shared_ptr storage_factory) { VLOG(1) << "Set internal KV Storage Engine"; - OpenCLRuntime::Configure(storage_engine); + kStorageFactory = storage_factory; } void ConfigOmpThreads(int omp_num_threads) { diff --git a/mace/core/runtime/opencl/opencl_runtime.cc b/mace/core/runtime/opencl/opencl_runtime.cc index 89db2e9b03141518c76f0703df231da4049ac30c..9d7045f2ca4728f4a76cc4ced522dab4151392ac 100644 --- a/mace/core/runtime/opencl/opencl_runtime.cc +++ b/mace/core/runtime/opencl/opencl_runtime.cc @@ -12,7 +12,7 @@ #include #include -#include "mace/core/file_storage_engine.h" +#include "mace/core/file_storage.h" #include "mace/core/runtime/opencl/opencl_extension.h" #include "mace/public/mace.h" #include "mace/utils/tuner.h" @@ -182,7 +182,6 @@ void OpenCLProfilingTimer::ClearTiming() { GPUPerfHint OpenCLRuntime::kGPUPerfHint = GPUPerfHint::PERF_DEFAULT; GPUPriorityHint OpenCLRuntime::kGPUPriorityHint = GPUPriorityHint::PRIORITY_DEFAULT; -std::shared_ptr OpenCLRuntime::kStorageEngine(nullptr); OpenCLRuntime *OpenCLRuntime::Global() { static OpenCLRuntime runtime(kGPUPerfHint, kGPUPriorityHint); @@ -194,9 +193,6 @@ void OpenCLRuntime::Configure(GPUPerfHint gpu_perf_hint, OpenCLRuntime::kGPUPerfHint = gpu_perf_hint; OpenCLRuntime::kGPUPriorityHint = gpu_priority_hint; } -void OpenCLRuntime::Configure(std::shared_ptr storage_engine) { - OpenCLRuntime::kStorageEngine = std::move(storage_engine); -} void GetAdrenoContextProperties(std::vector *properties, GPUPerfHint gpu_perf_hint, @@ -239,7 +235,8 @@ void GetAdrenoContextProperties(std::vector *properties, } OpenCLRuntime::OpenCLRuntime(GPUPerfHint gpu_perf_hint, - GPUPriorityHint gpu_priority_hint) { + GPUPriorityHint gpu_priority_hint): + storage_(nullptr) { LoadOpenCLLibrary(); std::vector all_platforms; @@ -312,17 +309,16 @@ OpenCLRuntime::OpenCLRuntime(GPUPerfHint gpu_perf_hint, &err); MACE_CHECK_CL_SUCCESS(err); - this->program_map_changed = false; + this->program_map_changed_ = false; - if (kStorageEngine == nullptr) { + extern std::shared_ptr kStorageFactory; + if (kStorageFactory != nullptr) { const std::string cl_compiled_file_name = "mace_cl_compiled_program.bin"; - kStorageEngine = std::move( - std::unique_ptr( - new FileStorageEngine(cl_compiled_file_name))); - } + storage_ = kStorageFactory->CreateStorage(cl_compiled_file_name); - if (platform_info_ != kCompiledProgramPlatform) { - kStorageEngine->Read(&program_content_map_); + if (platform_info_ != kCompiledProgramPlatform) { + storage_->Load(); + } } } @@ -377,12 +373,13 @@ bool OpenCLRuntime::BuildProgramFromCache( const std::string &build_options_str, cl::Program *program) { // Find from binary - auto it_content = this->program_content_map_.find(built_program_key); - if (it_content == this->program_content_map_.end()) { + if (this->storage_ == nullptr) return false; + auto content = this->storage_->Find(built_program_key); + if (content == nullptr) { return false; } - *program = cl::Program(context(), {device()}, {it_content->second}); + *program = cl::Program(context(), {device()}, {*content}); cl_int ret = program->build({device()}, build_options_str.c_str()); if (ret != CL_SUCCESS) { if (program->getBuildInfo(device()) == @@ -451,9 +448,11 @@ void OpenCLRuntime::BuildProgramFromSource( reinterpret_cast(program_binaries[0].get()) + program_binary_sizes[0]); - this->program_content_map_.emplace(built_program_key, - content); - this->program_map_changed = true; + if (this->storage_ != nullptr) { + this->storage_->Insert(built_program_key, content); + this->program_map_changed_ = true; + } + VLOG(3) << "Program from source: " << built_program_key; } } @@ -504,9 +503,9 @@ cl::Kernel OpenCLRuntime::BuildKernel( } void OpenCLRuntime::SaveBuiltCLProgram() { - if (program_map_changed) { - kStorageEngine->Write(program_content_map_); - program_map_changed = false; + if (program_map_changed_ && storage_ != nullptr) { + storage_->Flush(); + program_map_changed_ = false; } } diff --git a/mace/core/runtime/opencl/opencl_runtime.h b/mace/core/runtime/opencl/opencl_runtime.h index d0a509328e149a174c9176122e1259a8a8e82b22..f6cf4815ce7f2264fe1859f157258b55538095bc 100644 --- a/mace/core/runtime/opencl/opencl_runtime.h +++ b/mace/core/runtime/opencl/opencl_runtime.h @@ -56,7 +56,7 @@ class OpenCLRuntime { public: static OpenCLRuntime *Global(); static void Configure(GPUPerfHint, GPUPriorityHint); - static void Configure(std::shared_ptr storage_engine); + static void Configure(std::shared_ptr storage_engine); cl::Context &context(); cl::Device &device(); @@ -108,16 +108,15 @@ class OpenCLRuntime { std::shared_ptr device_; std::shared_ptr command_queue_; std::map built_program_map_; - std::map> program_content_map_; std::mutex program_build_mutex_; GPUType gpu_type_; std::string opencl_version_; std::string platform_info_; - bool program_map_changed; + bool program_map_changed_; + std::unique_ptr storage_; static GPUPerfHint kGPUPerfHint; static GPUPriorityHint kGPUPriorityHint; - static std::shared_ptr kStorageEngine; }; } // namespace mace diff --git a/mace/examples/example.cc b/mace/examples/example.cc index 9a50c0aac0d469a886922fb234f166372c461c9e..e70025d6c171087fad4393bc3620f728517ac564 100644 --- a/mace/examples/example.cc +++ b/mace/examples/example.cc @@ -157,9 +157,13 @@ bool RunModel(const std::vector &input_names, const std::string kernel_file_path = "/data/local/tmp/mace_run/cl"; + // Config internal kv storage factory. + std::shared_ptr storage_factory( + new FileStorageFactory(kernel_file_path)); + ConfigKVStorageFactory(storage_factory); // Init model mace::MaceEngine engine(&net_def, device_type, input_names, - output_names, kernel_file_path); + output_names); if (device_type == DeviceType::OPENCL || device_type == DeviceType::HEXAGON) { mace::MACE_MODEL_TAG::UnloadModelData(model_data); } diff --git a/mace/public/mace.h b/mace/public/mace.h index 13469db278f2d71f7766f9e07cc5e94a31830c73..db57fbcb9eaf27c3f8ea2f16ba062c6ca73a09fd 100644 --- a/mace/public/mace.h +++ b/mace/public/mace.h @@ -54,8 +54,7 @@ class MaceEngine { explicit MaceEngine(const NetDef *net_def, DeviceType device_type, const std::vector &input_nodes, - const std::vector &output_nodes, - const std::string &internal_storage_path); + const std::vector &output_nodes); ~MaceEngine(); MaceStatus Run(const std::map &inputs, diff --git a/mace/public/mace_runtime.h b/mace/public/mace_runtime.h index 0c8eef59724d58641cc2944870a4e7fe022c03e9..55397701397647318bfefbbb0b2a3a443c502ae7 100644 --- a/mace/public/mace_runtime.h +++ b/mace/public/mace_runtime.h @@ -31,16 +31,36 @@ enum GPUPriorityHint { enum CPUPowerOption { DEFAULT = 0, HIGH_PERFORMANCE = 1, BATTERY_SAVE = 2 }; -class KVStorageEngine { +class KVStorage { public: - virtual void Write( - const std::map> &data) = 0; - virtual void Read( - std::map> *data) = 0; + virtual void Load() = 0; + virtual bool Insert(const std::string &key, + const std::vector &value) = 0; + virtual std::vector *Find(const std::string &key) = 0; + virtual void Flush() = 0; }; +class KVStorageFactory { + public: + virtual std::unique_ptr CreateStorage(const std::string &name) = 0; +}; + +class FileStorageFactory : public KVStorageFactory { + public: + explicit FileStorageFactory(const std::string &path); + + ~FileStorageFactory(); + + std::unique_ptr CreateStorage(const std::string &name) override; + + private: + class Impl; + std::unique_ptr impl_; +}; + +void ConfigKVStorageFactory(std::shared_ptr storage_factory); + void ConfigOpenCLRuntime(GPUPerfHint, GPUPriorityHint); -void ConfigKVStorageEngine(std::shared_ptr storage_engine); void ConfigOmpThreads(int omp_num_threads); void ConfigCPUPowerOption(CPUPowerOption power_option); diff --git a/mace/python/tools/binary_codegen.py b/mace/python/tools/binary_codegen.py index 4f03a5f6995fa99415f300c70e88026a8963ed2a..21c6a84929e3527dd2b1e97feb4e9473d7a03ffa 100644 --- a/mace/python/tools/binary_codegen.py +++ b/mace/python/tools/binary_codegen.py @@ -25,6 +25,7 @@ def generate_cpp_source(): with open(binary_path, "rb") as f: binary_array = np.fromfile(f, dtype=np.uint8) + print "Generate binary", binary_path idx = 0 size, = struct.unpack("Q", binary_array[idx:idx+8]) idx += 8 diff --git a/mace/python/tools/opencl_codegen.py b/mace/python/tools/opencl_codegen.py index 220b8a18f54be3bf807e75c522c57350eb5e9ff7..18829635bce120a5dc9d912d4f66f76ef8e08239 100644 --- a/mace/python/tools/opencl_codegen.py +++ b/mace/python/tools/opencl_codegen.py @@ -14,15 +14,16 @@ FLAGS = None def generate_cpp_source(): - cl_built_kernel_file_name = 'mace_cl_compiled_program.bin' - cl_platform_info_file_name = 'mace_cl_platform_info.txt' maps = {} platform_info = '' - for binary_dir in FLAGS.cl_binary_dirs.split(","): - binary_path = os.path.join(binary_dir, cl_built_kernel_file_name) + binary_dirs = FLAGS.cl_binary_dirs.strip().split(",") + for binary_dir in binary_dirs: + binary_path = os.path.join(binary_dir, FLAGS.built_kernel_file_name) + print 'Before generate opencl code:', binary_path if not os.path.exists(binary_path): continue + print 'generate opencl code:', binary_path with open(binary_path, "rb") as f: binary_array = np.fromfile(f, dtype=np.uint8) @@ -43,7 +44,7 @@ def generate_cpp_source(): for ele in value: maps[key].append(hex(ele)) - cl_platform_info_path = os.path.join(binary_dir, cl_platform_info_file_name) + cl_platform_info_path = os.path.join(binary_dir, FLAGS.platform_info_file_name) with open(cl_platform_info_path, 'r') as f: curr_platform_info = f.read() if platform_info != "": @@ -76,6 +77,16 @@ def parse_args(): type=str, default="", help="The cl binaries directories.") + parser.add_argument( + "--built_kernel_file_name", + type=str, + default="", + help="The cl binaries directories.") + parser.add_argument( + "--platform_info_file_name", + type=str, + default="", + help="The cl binaries directories.") parser.add_argument( "--output_path", type=str, diff --git a/mace/tools/validation/mace_run.cc b/mace/tools/validation/mace_run.cc index a57acd0dc58f10332fd91325c86ae81230cdd91d..d4fa7c29a00073b9aff74d0a107e620540fc45cb 100644 --- a/mace/tools/validation/mace_run.cc +++ b/mace/tools/validation/mace_run.cc @@ -228,6 +228,9 @@ bool RunModel(const std::vector &input_names, // Init model LOG(INFO) << "Run init"; + std::shared_ptr storage_factory( + new FileStorageFactory(kernel_file_path)); + ConfigKVStorageFactory(storage_factory); mace::MaceEngine engine(&net_def, device_type, input_names, output_names); if (device_type == DeviceType::OPENCL || device_type == DeviceType::HEXAGON) { mace::MACE_MODEL_TAG::UnloadModelData(model_data); diff --git a/tools/env.sh b/tools/env.sh index 4308e272e23d9446060cda4495aa3d50edbad64c..634fb93c6d5bf6726c461066d60446601ca8b62a 100644 --- a/tools/env.sh +++ b/tools/env.sh @@ -9,6 +9,8 @@ MODEL_CODEGEN_DIR=${CODEGEN_DIR}/models/${MODEL_TAG} CL_CODEGEN_DIR=${CODEGEN_DIR}/opencl TUNING_CODEGEN_DIR=${CODEGEN_DIR}/tuning VERSION_SOURCE_PATH=${CODEGEN_DIR}/version +CL_BUILT_KERNEL_FILE_NAME=mace_cl_compiled_program.bin +CL_PLATFORM_INFO_FILE_NAME=mace_cl_platform_info.txt if [ -z ${EMBED_MODEL_DATA} ]; then EMBED_MODEL_DATA=1 fi diff --git a/tools/generate_opencl_code.sh b/tools/generate_opencl_code.sh index 381ce19df27a77c017adc03818cd887f68c6696d..37d1fb10c9e3f2474e7000c29d58cfb5aeed5a9e 100644 --- a/tools/generate_opencl_code.sh +++ b/tools/generate_opencl_code.sh @@ -26,6 +26,8 @@ if [ x"$TYPE" == x"source" ];then elif [ x"$#" == x"1" ];then python mace/python/tools/opencl_codegen.py \ + --built_kernel_file_name=${CL_BUILT_KERNEL_FILE_NAME} \ + --platform_info_file_name=${CL_PLATFORM_INFO_FILE_NAME} \ --output_path=${CL_CODEGEN_DIR}/opencl_compiled_program.cc || exit 1 else @@ -39,14 +41,17 @@ else if [ "$PULL_OR_NOT" = 1 ]; then CL_BIN_DIR=${CL_BIN_DIRS} - rm -rf ${CL_BIN_DIR} mkdir -p ${CL_BIN_DIR} + rm -rf ${CL_BIN_DIR}/${CL_BUILT_KERNEL_FILE_NAME} + rm -rf ${CL_BIN_DIR}/${CL_PLATFORM_INFO_FILE_NAME} if [ x"$TARGET_ABI" != x"host" ]; then adb -s $DEVICE_ID pull ${COMPILED_PROGRAM_DIR}/. ${CL_BIN_DIR} > /dev/null fi fi python mace/python/tools/opencl_codegen.py \ + --built_kernel_file_name=${CL_BUILT_KERNEL_FILE_NAME} \ + --platform_info_file_name=${CL_PLATFORM_INFO_FILE_NAME} \ --cl_binary_dirs=${CL_BIN_DIRS} \ --output_path=${CL_CODEGEN_DIR}/opencl_compiled_program.cc || exit 1 fi diff --git a/tools/generate_tuning_param_code.sh b/tools/generate_tuning_param_code.sh index 11d250e40cc5ce394b19f9749ab54c962b23f963..4d116c9fec7c140a2078e0d6f28e1c5181468e51 100644 --- a/tools/generate_tuning_param_code.sh +++ b/tools/generate_tuning_param_code.sh @@ -24,8 +24,8 @@ else fi if [ "$PULL_OR_NOT" = 1 ]; then - rm -rf ${BIN_DIRS} mkdir -p ${BIN_DIRS} + rm -rf ${BIN_DIRS}/mace_run.config if [ x"$TARGET_ABI" != x"host" ]; then adb -s $DEVICE_ID pull ${PHONE_DATA_DIR}/mace_run.config ${BIN_DIRS} > /dev/null fi diff --git a/tools/mace_tools.py b/tools/mace_tools.py index bfe73bafb1576c676e84ce71b72fa682800ea33d..d739bc41f873646adb3f8cb7a572134a763f9cb1 100644 --- a/tools/mace_tools.py +++ b/tools/mace_tools.py @@ -251,7 +251,6 @@ def merge_libs_and_tuning_results(target_soc, output_dir, model_output_dirs): build_production_code() model_output_dirs_str = ",".join(model_output_dirs) - print output_dir, model_output_dirs command = "bash tools/merge_libs.sh {} {} {}".format(target_soc, output_dir, model_output_dirs_str) run_command(command)