Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #ifndef DUMP_TENSOR_PLUGIN_H
11 : #define DUMP_TENSOR_PLUGIN_H
12 :
13 : #include <cstdint>
14 : #include <vector>
15 : #include <map>
16 : #include <mutex>
17 : #include "common/singleton.h"
18 : #include "adx_exception_callback.h"
19 :
20 : namespace Adx {
21 : using AdumpPluginInitFunc = int32_t (*)();
22 : using AdumpPluginInit = int32_t ();
23 :
24 : class DumpTensorPlugin : public Adx::Common::Singleton::Singleton<DumpTensorPlugin> {
25 : public:
26 3 : DumpTensorPlugin() {}
27 : ~DumpTensorPlugin() override;
28 : int32_t InitPluginLib();
29 : void HeadCallbackRegister(DfxTensorType tensorType, HeadProcess headProcess);
30 : void TensorCallbackRegister(DfxTensorType tensorType, TensorProcess tensorProcess);
31 : int32_t NotifyHeadCallback(DfxTensorType tensorType, uint32_t devId, const void *addr, uint64_t headerSize,
32 : uint64_t &newHeaderSize);
33 : int32_t NotifyTensorCallback(DfxTensorType tensorType, uint32_t devId, const void *addr, uint64_t size, int32_t fd);
34 : bool IsTensorTypeRegistered(DfxTensorType tensorType);
35 :
36 : private:
37 : void ReceiveInitialFunc(void *handle) const;
38 : std::mutex dlopenMtx_;
39 : std::mutex regMtx_;
40 : std::vector<void *> pluginLibHandles_;
41 : std::map<DfxTensorType, HeadProcess> headProcessMap_;
42 : std::map<DfxTensorType, TensorProcess> tensorProcessMap_;
43 : };
44 :
45 : } // namespace Adx
46 : #endif
|