11/* *********************************************************************************/
2- /* This file is part of spla project */
3- /* https://github.com/SparseLinearAlgebra/spla */
2+ /* This file is part of spla project */
3+ /* https://github.com/SparseLinearAlgebra/spla */
44/* *********************************************************************************/
5- /* MIT License */
5+ /* MIT License */
66/* */
7- /* Copyright (c) 2023 SparseLinearAlgebra */
7+ /* Copyright (c) 2023 SparseLinearAlgebra */
88/* */
9- /* Permission is hereby granted, free of charge, to any person obtaining a copy */
10- /* of this software and associated documentation files (the "Software"), to deal */
11- /* in the Software without restriction, including without limitation the rights */
12- /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13- /* copies of the Software, and to permit persons to whom the Software is */
14- /* furnished to do so, subject to the following conditions: */
9+ /* Permission is hereby granted, free of charge, to any person obtaining a copy
10+ */
11+ /* of this software and associated documentation files (the "Software"), to deal
12+ */
13+ /* in the Software without restriction, including without limitation the rights
14+ */
15+ /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
16+ /* copies of the Software, and to permit persons to whom the Software is */
17+ /* furnished to do so, subject to the following conditions: */
1518/* */
16- /* The above copyright notice and this permission notice shall be included in all */
17- /* copies or substantial portions of the Software. */
19+ /* The above copyright notice and this permission notice shall be included in
20+ * all */
21+ /* copies or substantial portions of the Software. */
1822/* */
19- /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20- /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21- /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22- /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23- /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24- /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25- /* SOFTWARE. */
23+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
24+ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
25+ /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+ */
27+ /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
28+ /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+ */
30+ /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+ */
32+ /* SOFTWARE. */
2633/* *********************************************************************************/
2734
2835#include " common.hpp"
2936#include " options.hpp"
3037
31- #include < spla.hpp>
3238#include < iostream>
39+ #include < spla.hpp>
3340
34- int main (int argc, const char * const * argv) {
35- auto options = make_options (" mst" , " Boruvka's Minimum Spanning Tree algorithm with spla library" );
36-
37- cxxopts::ParseResult args;
38- int ret;
39-
40- if (parse_options (argc, argv, options, args, ret)) {
41- std::cerr << " failed to parse options" << std::endl;
42- return ret;
43- }
44-
45- spla::Timer timer_total;
46- spla::Timer timer_gpu;
47- spla::Timer timer_ref;
48- spla::MtxLoader loader;
49-
50- timer_total.start ();
51-
52- if (!loader.load (args[" mtxpath" ].as <std::string>())) {
53- std::cerr << " failed to load graph" ;
54- return 1 ;
55- }
56-
57- std::string acc_info;
58- spla::Library* library = spla::Library::get ();
59-
60- library->set_platform (args[" platform" ].as <int >());
61- library->set_device (args[" device" ].as <int >());
62- library->set_queues_count (1 );
63- library->get_accelerator_info (acc_info);
64- std::cout << " env: " << acc_info << std::endl;
65-
66- const spla::uint N = loader.get_n_rows ();
67- auto S = spla::Matrix::make (N, N, spla::PAIR );
68-
69- const auto & Ai = loader.get_Ai ();
70- const auto & Aj = loader.get_Aj ();
71- const auto & Aw = loader.get_Aw ();
72-
73- for (std::size_t k = 0 ; k < loader.get_n_values (); ++k) {
41+ int main (int argc, const char *const *argv) {
42+ auto options = make_options (
43+ " mst" , " Boruvka's Minimum Spanning Tree algorithm with spla library" );
44+
45+ cxxopts::ParseResult args;
46+ int ret;
47+
48+ if (parse_options (argc, argv, options, args, ret)) {
49+ std::cerr << " failed to parse options" << std::endl;
50+ return ret;
51+ }
52+
53+ spla::Timer timer_total;
54+ spla::Timer timer_gpu;
55+ spla::Timer timer_ref;
56+ spla::MtxLoader loader;
57+
58+ timer_total.start ();
59+
60+ if (!loader.load (args[" mtxpath" ].as <std::string>())) {
61+ std::cerr << " failed to load graph" ;
62+ return 1 ;
63+ }
64+
65+ std::string acc_info;
66+ spla::Library *library = spla::Library::get ();
67+
68+ library->set_platform (args[" platform" ].as <int >());
69+ library->set_device (args[" device" ].as <int >());
70+ library->set_queues_count (1 );
71+ library->get_accelerator_info (acc_info);
72+ std::cout << " env: " << acc_info << std::endl;
73+
74+ const spla::uint N = loader.get_n_rows ();
75+ auto S = spla::Matrix::make (N, N, spla::PAIR );
76+
77+ const auto &Ai = loader.get_Ai ();
78+ const auto &Aj = loader.get_Aj ();
79+ const auto &Aw = loader.get_Aw ();
80+
81+ for (std::size_t k = 0 ; k < loader.get_n_values (); ++k) {
82+ S->set_pair (Ai[k], Aj[k], spla::T_PAIR (Aw[k], Aj[k]));
83+ }
84+
85+ auto T_gpu = spla::Matrix::make (N, N, spla::FLOAT );
86+
87+ auto desc = spla::Descriptor::make ();
88+
89+ const int n_iters = args[" niters" ].as <int >();
90+
91+ double total_weight_gpu = 0.0 ;
92+
93+ if (args[" run-gpu" ].as <bool >()) {
94+ library->set_force_no_acceleration (false );
95+
96+ for (int i = 0 ; i < n_iters; ++i) {
97+ T_gpu->clear ();
98+ S = spla::Matrix::make (N, N, spla::PAIR );
99+ for (std::size_t k = 0 ; k < loader.get_n_values (); ++k) {
74100 S->set_pair (Ai[k], Aj[k], spla::T_PAIR (Aw[k], Aj[k]));
101+ }
102+ timer_gpu.lap_begin ();
103+ spla::mst (T_gpu, S, desc, nullptr );
104+ timer_gpu.lap_end ();
75105 }
76-
77- auto T_gpu = spla::Matrix::make (N, N, spla::FLOAT );
78-
79- auto desc = spla::Descriptor::make ();
80-
81- const int n_iters = args[" niters" ].as <int >();
82-
83- double total_weight_gpu = 0.0 ;
84-
85- if (args[" run-gpu" ].as <bool >()) {
86- library->set_force_no_acceleration (false );
87-
88- for (int i = 0 ; i < n_iters; ++i) {
89- T_gpu->clear ();
90- S = spla::Matrix::make (N, N, spla::PAIR );
91- for (std::size_t k = 0 ; k < loader.get_n_values (); ++k) {
92- S->set_pair (Ai[k], Aj[k], spla::T_PAIR (Aw[k], Aj[k]));
93- }
94- timer_gpu.lap_begin ();
95- spla::mst (T_gpu, S, desc, nullptr );
96- timer_gpu.lap_end ();
97- }
98-
99- total_weight_gpu = 0 ;
100- for (spla::uint i = 0 ; i < N; ++i) {
101- for (spla::uint j = i + 1 ; j < N; ++j) {
102- float w;
103- T_gpu->get_float (i, j, w);
104- if (w != 0.0 ) {
105- total_weight_gpu += w;
106- }
107- }
106+
107+ total_weight_gpu = 0 ;
108+ for (spla::uint i = 0 ; i < N; ++i) {
109+ for (spla::uint j = i + 1 ; j < N; ++j) {
110+ float w;
111+ T_gpu->get_float (i, j, w);
112+ if (w != 0.0 ) {
113+ total_weight_gpu += w;
108114 }
109-
110- std::cout << " GPU MST total weight: " << total_weight_gpu << std::endl;
115+ }
111116 }
112-
113- spla::Library::get ()->finalize ();
114-
115- timer_total.stop ();
116-
117- std::cout << " \n === Timing Results ===" << std::endl;
118- std::cout << " total(ms):" << timer_total.get_elapsed_ms () << std::endl;
119- std::cout << " gpu(ms): " ;
120- timer_gpu.print ();
121- std::cout << std::endl;
122-
123- return 0 ;
117+
118+ std::cout << " GPU MST total weight: " << total_weight_gpu << std::endl;
119+ }
120+
121+ spla::Library::get ()->finalize ();
122+
123+ timer_total.stop ();
124+
125+ std::cout << " \n === Timing Results ===" << std::endl;
126+ std::cout << " total(ms):" << timer_total.get_elapsed_ms () << std::endl;
127+ std::cout << " gpu(ms): " ;
128+ timer_gpu.print ();
129+ std::cout << std::endl;
130+
131+ return 0 ;
124132}
0 commit comments