55#include < cmath>
66#include < utility>
77
8+ void Component::init () {
9+ #ifdef TRACK_STATISTICS
10+ transistor_count_ = calc_transistor_count ();
11+ static_power_ = calc_static ();
12+ dynamic_power_ = calc_dynamic ();
13+ width_ = calc_width ();
14+ height_ = calc_height ();
15+ #ifdef USE_CUDA
16+ internal_mask = cv::cuda::GpuMat (rows_, cols_, CV_8U , cv::Scalar (0 ));
17+ array_transistor_count_ = cv::cuda::GpuMat (rows_, cols_, CV_32S , cv::Scalar (0 ));
18+ array_static_energy_ = cv::UMat (rows_, cols_, CV_64F , cv::Scalar (0 ));
19+ array_dynamic_energy_ = cv::UMat (rows_, cols_, CV_64F , cv::Scalar (0 ));
20+ #else
21+ internal_mask = cv::UMat (rows_, cols_, CV_8U , cv::Scalar (0 ));
22+ array_transistor_count_ = cv::UMat (rows_, cols_, CV_32S , cv::Scalar (0 ));
23+ array_static_energy_ = cv::UMat (rows_, cols_, CV_64F , cv::Scalar (0 ));
24+ array_dynamic_energy_ = cv::UMat (rows_, cols_, CV_64F , cv::Scalar (0 ));
25+ #endif
26+ this ->calc_internal_mask ();
27+ #endif
28+ }
29+
830void Component::calc_internal_mask () {
9- cv::Mat im = this ->internal_mask .getMat (cv::ACCESS_WRITE );
31+ cv::Mat im;
32+ #ifdef USE_CUDA
33+ this ->internal_mask .download (im);
34+ #else
35+ im = this ->internal_mask .getMat (cv::ACCESS_WRITE );
36+ #endif
1037 for (int row = 0 ; row < rows_; row += row_stride_) {
1138 for (int col = 0 ; col < cols_; col += col_stride_) {
1239 im.at <uint8_t >(row, col) = 1 ;
1340 }
1441 }
42+ #ifdef USE_CUDA
43+ this ->internal_mask .upload (im);
44+ #endif
1545}
1646
1747void Component::set_process_node (int process_node) {
@@ -58,7 +88,13 @@ cv::Mat Component::get_transistor_count_array() {
5888#ifdef TRACK_STATISTICS
5989 array_transistor_count_.setTo (transistor_count_, this ->internal_mask );
6090#endif
91+ #ifdef USE_CUDA
92+ cv::Mat m;
93+ this ->array_transistor_count_ .download (m);
94+ return m;
95+ #else
6196 return this ->array_transistor_count_ .getMat (cv::ACCESS_READ );
97+ #endif
6298}
6399
64100int Component::get_transistor_count () {
@@ -73,6 +109,22 @@ double Component::get_height() {
73109 return this ->height_ ;
74110}
75111
112+ double Component::scale_speed (double base) {
113+ double sf = 7.6 - 0.961 * log (5.531 * config_->get_clock_rate () - 104.456 );
114+ return base * sf;
115+ }
116+
117+ double Component::scale_width (double base) {
118+ // Scale with process node
119+ double sf = (double ) config_->get_process_node () / this ->process_node_ ;
120+ return base * sf;
121+ }
122+
123+ double Component::scale_height (double base) {
124+ double sf = (double ) config_->get_process_node () / this ->process_node_ ;
125+ return base * sf;
126+ }
127+
76128int Component::calc_transistor_count () {
77129 return 0 ;
78130}
@@ -93,22 +145,6 @@ double Component::calc_height() {
93145 return 0 ;
94146}
95147
96- double Component::scale_speed (double base) {
97- double sf = 7.6 - 0.961 * log (5.531 * config_->get_clock_rate () - 104.456 );
98- return base * sf;
99- }
100-
101- double Component::scale_width (double base) {
102- // Scale with process node
103- double sf = (double ) config_->get_process_node () / this ->process_node_ ;
104- return base * sf;
105- }
106-
107- double Component::scale_height (double base) {
108- double sf = (double ) config_->get_process_node () / this ->process_node_ ;
109- return base * sf;
110- }
111-
112148#endif
113149
114150RTTR_REGISTRATION {
0 commit comments