123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- #ifndef EDK_MLU_CONTEXT_H_
- #define EDK_MLU_CONTEXT_H_
- #include <functional>
- #include <memory>
- #include <utility>
- #include "cxxutil/edk_attribute.h"
- #include "cxxutil/exception.h"
- namespace edk {
- enum class CoreVersion {
- MLU220 = 1,
- MLU270 = 2,
- };
- struct MluTaskQueuePrivate;
- class MluTaskQueueProxy;
- struct MluTaskQueue {
- public:
-
- static std::shared_ptr<MluTaskQueue> Create();
-
- void Sync();
-
- class Mark {
- public:
-
- Mark(std::function<void(int)> release, int idx) : release_(release), idx_(idx) {}
-
- ~Mark() {
- if (release_) release_(idx_);
- }
-
- Mark(Mark&& other) : release_(std::move(other.release_)), idx_(other.idx_) { other.release_ = nullptr; }
-
- Mark& operator=(Mark&& other) {
- release_ = std::move(other.release_);
- idx_ = other.idx_;
- other.release_ = nullptr;
- return *this;
- }
-
- int Index() const noexcept { return idx_; }
- private:
- Mark() = delete;
- Mark(const Mark&) = delete;
- Mark& operator=(const Mark&) = delete;
- std::function<void(int)> release_{nullptr};
- int idx_{0};
- };
-
- Mark PlaceMark();
-
- float Count(const Mark& start, const Mark& end) const;
- private:
- struct _PrivDelete {
- void operator()(MluTaskQueuePrivate* p);
- };
- friend class MluTaskQueueProxy;
- MluTaskQueue();
- std::unique_ptr<MluTaskQueuePrivate, _PrivDelete> priv_{nullptr};
- };
- using MluTaskQueue_t = std::shared_ptr<MluTaskQueue>;
- class MluContext {
- public:
-
- MluContext() = default;
-
- explicit MluContext(int dev_id) : dev_id_(dev_id) {}
-
- inline int DeviceId() const { return dev_id_; }
-
- inline void SetDeviceId(int id) { dev_id_ = id; }
-
- static uint32_t GetDeviceNum();
-
- static bool CheckDeviceId(int id);
-
- attribute_deprecated inline int ChannelId() const { return channel_id_; }
-
- attribute_deprecated inline void SetChannelId(int id) { channel_id_ = id; }
-
- void BindDevice();
-
- CoreVersion GetCoreVersion();
- private:
- int dev_id_ = 0;
- int channel_id_ = -1;
- };
- }
- #endif
|