forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathdsp_selector.cpp
More file actions
64 lines (53 loc) · 1.23 KB
/
dsp_selector.cpp
File metadata and controls
64 lines (53 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "dsp_selector.h"
#include <string>
#include <stdexcept>
#ifdef __DSP
namespace base_device
{
namespace memory
{
// Global selector instance
std::unique_ptr<DspSelector> dsp_selector = nullptr;
// Get current DSP selector
DspSelector* get_dsp_selector()
{
if (!dsp_selector)
{
throw std::runtime_error(
"ModuleBase::memory::get_dsp_selector: "
"DSP selector not initialized. Call init_dsp_selector first."
);
}
return dsp_selector.get();
}
// Default DSP selector implementation
class DefaultDspSelector : public DspSelector
{
private:
int rank_ = 0;
public:
int get_rank() const override
{
return rank_;
}
void set_rank(const int rank) override
{
if (rank < 0)
{
throw std::runtime_error(
"ModuleBase::memory::DspSelector: "
"DSP rank must be non-negative"
);
}
rank_ = rank;
}
};
// Create default DSP selector and set it as global
void create_default_selector(const int rank)
{
dsp_selector = std::unique_ptr<DefaultDspSelector>(new DefaultDspSelector());
dsp_selector->set_rank(rank);
}
} // namespace memory
} // namespace base_device
#endif