提交 240a685f 编写于 作者: M Megvii Engine Team

feat(opencl): opt lite-OpenCL api: opencl_clear_global_data

and enable_opencl_deploy lite api

GitOrigin-RevId: 9d932ff27e16011448f5d1c0fa63d0ed737d842c
上级 4f60fbbb
......@@ -16,6 +16,7 @@
#include "decryption/rc4_cryption.h"
#include "lite/global.h"
#include "misc.h"
#include "network_impl_base.h"
#include "parse_info/default_parse.h"
#include "parse_info/parse_info_base.h"
......
......@@ -51,6 +51,29 @@ LITE_API std::string ssprintf(const char* fmt = 0, ...)
*/
LITE_API void print_log(LiteLogLevel level, const char* format = 0, ...)
__attribute__((format(printf, 2, 3)));
/*!
* \brief NonCopyableObj base.
*/
class NonCopyableObj {
public:
NonCopyableObj() {}
private:
NonCopyableObj(const NonCopyableObj&);
NonCopyableObj& operator=(const NonCopyableObj&);
};
template <class T>
class Singleton : public NonCopyableObj {
public:
Singleton() {}
static T& Instance() {
static T _;
return _;
}
};
} // namespace lite
#if LITE_ENABLE_LOGGING
......
......@@ -16,10 +16,32 @@
#include "tensor_impl_base.h"
#include "type_info.h"
#include <atomic>
#include <unordered_map>
namespace lite {
/*!
* \brief network reference count
*/
class NetworkRefCount : public Singleton<NetworkRefCount> {
public:
NetworkRefCount() : count(0) {}
NetworkRefCount& operator++(int) {
++count;
return *this;
}
NetworkRefCount& operator--(int) {
--count;
return *this;
}
int refcount() { return count; }
private:
std::atomic<int> count;
};
/*!
* \brief the Inner IO data struct, add some inner data from IO
*/
......@@ -54,7 +76,8 @@ struct NetworkIOInner {
*/
class Network::NetworkImplBase : public DynTypeObj {
public:
virtual ~NetworkImplBase() = default;
virtual ~NetworkImplBase() { NetworkRefCount::Instance()--; };
NetworkImplBase() { NetworkRefCount::Instance()++; };
//! set the config of the network, include:
//! the inference device
......
......@@ -70,6 +70,19 @@ TEST(TestNetWork, Basic) {
compare_lite_tensor<float>(result_lite, result_mgb);
}
TEST(TestNetWork, RefCount) {
Config config;
ASSERT_EQ(NetworkRefCount::Instance().refcount(), 0);
std::shared_ptr<Network> network = std::make_shared<Network>(config);
ASSERT_EQ(NetworkRefCount::Instance().refcount(), 1);
std::shared_ptr<Network> network_s = std::make_shared<Network>(config);
ASSERT_EQ(NetworkRefCount::Instance().refcount(), 2);
network.reset();
ASSERT_EQ(NetworkRefCount::Instance().refcount(), 1);
network_s.reset();
ASSERT_EQ(NetworkRefCount::Instance().refcount(), 0);
}
TEST(TestNetWork, SetDeviceId) {
Config config;
auto lite_tensor = get_input_data("./input_data.npy");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册