提交 0b1021c6 编写于 作者: L liuqi

Add MT test for GPU Context and update the API document.

上级 021dbc5b
......@@ -100,6 +100,14 @@ void OpDefBuilder::Finalize(OperatorDef *op_def) const {
*op_def = op_def_;
}
namespace {
std::string GetStoragePathFromEnv() {
char *storage_path_str = getenv("MACE_INTERNAL_STORAGE_PATH");
if (storage_path_str == nullptr) return "";
return storage_path_str;
}
} // namespace
OpTestContext *OpTestContext::Get(int num_threads,
CPUAffinityPolicy cpu_affinity_policy,
bool use_gemmlowp) {
......@@ -112,7 +120,7 @@ OpTestContext *OpTestContext::Get(int num_threads,
OpTestContext::OpTestContext(int num_threads,
CPUAffinityPolicy cpu_affinity_policy,
bool use_gemmlowp)
: gpu_context_(new GPUContext()),
: gpu_context_(new GPUContext(GetStoragePathFromEnv())),
opencl_mem_types_({MemoryType::GPU_IMAGE}) {
device_map_[DeviceType::CPU] = std::unique_ptr<Device>(
new CPUDevice(num_threads,
......
......@@ -146,6 +146,9 @@ class MaceStatus {
///
/// There are some data in common between different MaceEngines using GPU,
/// use one GPUContext could avoid duplication.
///
/// Thread-safe.
/// You could use one GPUContext for multiple parallel MaceEngines.
class GPUContext;
/// \brief GPUContext builder.
......
......@@ -39,7 +39,6 @@ void MaceRunFunc(const int in_out_size) {
std::shared_ptr<NetDef> net_def(new NetDef());
std::vector<half> data;
ops::test::GenerateRandomRealTypeData<half>(filter_shape, &data);
AddTensor<half>(
......@@ -63,6 +62,7 @@ void MaceRunFunc(const int in_out_size) {
}
MaceEngineConfig config(DeviceType::GPU);
config.SetGPUContext(mace::ops::test::OpTestContext::Get()->gpu_context());
MaceEngine engine(config);
MaceStatus status = engine.Init(net_def.get(), input_names, output_names,
......
......@@ -901,6 +901,8 @@ class DeviceWrapper:
stdout_buf = []
process_output = sh_commands.make_output_processor(stdout_buf)
internal_storage_dir = self.create_internal_storage_dir()
if simpleperf and self.system == SystemType.android:
self.push(sh_commands.find_simpleperf_library(abi),
self.data_dir)
......@@ -909,6 +911,7 @@ class DeviceWrapper:
ld_preload,
'MACE_OUT_OF_RANGE_CHECK=%s' % out_of_range_check,
'MACE_OPENCL_PROFILING=%d' % opencl_profiling,
'MACE_INTERNAL_STORAGE_PATH=%s' % internal_storage_dir,
'MACE_CPP_MIN_VLOG_LEVEL=%d' % vlog_level,
simpleperf_cmd,
'stat',
......@@ -928,6 +931,7 @@ class DeviceWrapper:
ld_preload,
'MACE_OUT_OF_RANGE_CHECK=%d' % out_of_range_check,
'MACE_OPENCL_PROFILNG=%d' % opencl_profiling,
'MACE_INTERNAL_STORAGE_PATH=%s' % internal_storage_dir,
'MACE_CPP_MIN_VLOG_LEVEL=%d' % vlog_level,
device_bin_full_path,
args
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册