Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2a02b08
implement `extract_row` on CSR matrices for OpenCL backend
therain7 Nov 26, 2025
f8fdee8
implement `emult` on dense vectors for OpenCL backend
therain7 Nov 26, 2025
572f7d6
feat(type): register Pair type in type system
polka777 Apr 22, 2026
9cafb10
feat(matrix,vector,scalar): add Pair type support
polka777 Apr 22, 2026
204a7bc
feat(opencl pair) support pair in opencl, operations mxv, extract row…
polka777 Apr 22, 2026
5b54ef7
feat(io) support read matrix with weight
polka777 Apr 22, 2026
c5452bc
feat(mst) add algorithm mst, executable to CMakeLists
polka777 Apr 22, 2026
f9c95a4
feat(tests) test pair for operations, type registration and connectio…
polka777 Apr 22, 2026
239aea5
fix: tests
polka777 Apr 23, 2026
7752ae8
fix clang tidy code style
polka777 Apr 24, 2026
6952fa0
Clang-tidy format tests/
polka777 Apr 26, 2026
155e412
Clang-tidy format include/
polka777 Apr 26, 2026
b3f5266
Clang-tidy format src/
polka777 Apr 26, 2026
b1aaa66
Clang-tidy format examples/
polka777 Apr 26, 2026
3706036
Clang-tidy format src/
polka777 Apr 26, 2026
bdf4709
Clang-tidy format
polka777 Apr 26, 2026
60021c2
Merge PR #238 from Andrey
b08lsoai Jul 30, 2026
25f7025
fix: resolve vector out-of-bounds crash
b08lsoai Jul 30, 2026
424cbd7
fix: initialize cl program on cache miss
b08lsoai Jul 30, 2026
1810465
fix: repair opencl extract_row kernel
b08lsoai Aug 3, 2026
11f93b0
ref: make the macro definitions clearer
b08lsoai Aug 3, 2026
498010b
ref: remove unnecessary replace
b08lsoai Aug 3, 2026
042dbc7
fix: fix custom pair macro generation
b08lsoai Aug 16, 2026
a43d56f
fix: removed hardcoded logic
b08lsoai Aug 16, 2026
7ac5fc9
fix: add missing overrides for T_PAIR in TScalar
b08lsoai Aug 19, 2026
7cd50c7
fix: implement missing T_PAIR handling in TVector
b08lsoai Aug 19, 2026
2844fbf
feat: add a binary selector
b08lsoai Aug 20, 2026
04e7240
fix: add Scalar::make_pair
b08lsoai Aug 20, 2026
b680386
feat: add v_assign_bslct_masked
b08lsoai Aug 20, 2026
a65e8de
ref(mst): replace the loop with an opencl kernels
b08lsoai Aug 20, 2026
8af7c63
feat: add m_assign_bslct
b08lsoai Aug 23, 2026
0ebd095
style: format the code
b08lsoai Aug 23, 2026
5f14b72
ref: move matrix filtering to OpenCL kernel
b08lsoai Aug 23, 2026
d6dd44d
ref: move common part out of branching
b08lsoai Aug 24, 2026
94e80eb
test: add tests for *_assign_bslct
b08lsoai Aug 24, 2026
0028f77
fix: cpu register mxv for pair
b08lsoai Aug 24, 2026
9d923a8
fix: cpu register v_reduce for pair
b08lsoai Aug 24, 2026
f97555e
feat: cpu register v_assign_bslct for pair
b08lsoai Aug 24, 2026
29316fa
ref: correct the args order for v_assign_bslct
b08lsoai Aug 24, 2026
0476069
feat: cpu register m_assign_bslct for pair
b08lsoai Aug 24, 2026
4a65706
ref: remove unnecessary macros
b08lsoai Aug 25, 2026
aaf9c1a
fix: add cpu mode to mst
b08lsoai Aug 25, 2026
658ed33
feat: register *_assign_bslct for other types
b08lsoai Aug 25, 2026
7d6f648
test: add tests for *_assign_bslct
b08lsoai Aug 27, 2026
92128f7
feat: add EQ_INT op_select_bin for testing
b08lsoai Aug 27, 2026
41870db
fix: resolve data race in extract_row kernel
b08lsoai Aug 29, 2026
d4a12db
fix: preserve the matrix weights when saving
b08lsoai Aug 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ if (SPLA_BUILD_EXAMPLES)
spla_example_application(tc)
spla_example_application(pi)
spla_example_application(convert)
spla_example_application(mst)
endif ()

######################################################################
Expand Down
166 changes: 166 additions & 0 deletions examples/mst.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**********************************************************************************/
/* This file is part of spla project */
/* https://github.com/SparseLinearAlgebra/spla */
/**********************************************************************************/
/* MIT License */
/* */
/* Copyright (c) 2023 SparseLinearAlgebra */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy
*/
/* of this software and associated documentation files (the "Software"), to deal
*/
/* in the Software without restriction, including without limitation the rights
*/
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in
* all */
/* copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*/
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*/
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/
/* SOFTWARE. */
/**********************************************************************************/

#include "common.hpp"
#include "options.hpp"

#include <iostream>
#include <spla.hpp>

int main(int argc, const char* const* argv) {
auto options = make_options(
"mst", "Boruvka's Minimum Spanning Tree algorithm with spla library");

cxxopts::ParseResult args;
int ret;

if (parse_options(argc, argv, options, args, ret)) {
std::cerr << "failed to parse options" << std::endl;
return ret;
}

spla::Timer timer_total;
spla::Timer timer_gpu;
spla::Timer timer_cpu;
spla::Timer timer_ref;
spla::MtxLoader loader;

timer_total.start();

if (!loader.load(args["mtxpath"].as<std::string>())) {
std::cerr << "failed to load graph";
return 1;
}

std::string acc_info;
spla::Library* library = spla::Library::get();

library->set_platform(args["platform"].as<int>());
library->set_device(args["device"].as<int>());
library->set_queues_count(1);
library->get_accelerator_info(acc_info);
std::cout << "env: " << acc_info << std::endl;

const spla::uint N = loader.get_n_rows();
auto S = spla::Matrix::make(N, N, spla::PAIR);

const auto& Ai = loader.get_Ai();
const auto& Aj = loader.get_Aj();
const auto& Aw = loader.get_Aw();

for (std::size_t k = 0; k < loader.get_n_values(); ++k) {
S->set_pair(Ai[k], Aj[k], spla::T_PAIR(Aw[k], Aj[k]));
}

auto T_gpu = spla::Matrix::make(N, N, spla::FLOAT);
auto T_cpu = spla::Matrix::make(N, N, spla::FLOAT);

auto desc = spla::Descriptor::make();

const int n_iters = args["niters"].as<int>();

double total_weight_gpu = 0.0;
double total_weight_cpu = 0.0;

if (args["run-cpu"].as<bool>()) {
library->set_force_no_acceleration(true);

for (int i = 0; i < n_iters; ++i) {
T_cpu->clear();
S = spla::Matrix::make(N, N, spla::PAIR);
for (std::size_t k = 0; k < loader.get_n_values(); ++k) {
S->set_pair(Ai[k], Aj[k], spla::T_PAIR(Aw[k], Aj[k]));
}
timer_cpu.lap_begin();
spla::mst(T_cpu, S, desc, nullptr);
timer_cpu.lap_end();
}

total_weight_cpu = 0;
for (spla::uint i = 0; i < N; ++i) {
for (spla::uint j = i + 1; j < N; ++j) {
float w;
T_cpu->get_float(i, j, w);
if (w != 0.0) {
total_weight_cpu += w;
}
}
}

std::cout << "CPU MST total weight: " << total_weight_cpu << std::endl;
}

if (args["run-gpu"].as<bool>()) {
library->set_force_no_acceleration(false);

for (int i = 0; i < n_iters; ++i) {
T_gpu->clear();
S = spla::Matrix::make(N, N, spla::PAIR);
for (std::size_t k = 0; k < loader.get_n_values(); ++k) {
S->set_pair(Ai[k], Aj[k], spla::T_PAIR(Aw[k], Aj[k]));
}
timer_gpu.lap_begin();
spla::mst(T_gpu, S, desc, nullptr);
timer_gpu.lap_end();
}

total_weight_gpu = 0;
for (spla::uint i = 0; i < N; ++i) {
for (spla::uint j = i + 1; j < N; ++j) {
float w;
T_gpu->get_float(i, j, w);
if (w != 0.0) {
total_weight_gpu += w;
}
}
}

std::cout << "GPU MST total weight: " << total_weight_gpu << std::endl;
}

spla::Library::get()->finalize();

timer_total.stop();

std::cout << "\n=== Timing Results ===" << std::endl;
std::cout << "total(ms):" << timer_total.get_elapsed_ms() << std::endl;
std::cout << "cpu(ms): ";
timer_cpu.print();
std::cout << std::endl;
std::cout << "gpu(ms): ";
timer_gpu.print();
std::cout << std::endl;

return 0;
}
1 change: 1 addition & 0 deletions include/spla.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "spla/memview.hpp"
#include "spla/object.hpp"
#include "spla/op.hpp"
#include "spla/pair.hpp"
#include "spla/ref.hpp"
#include "spla/scalar.hpp"
#include "spla/schedule.hpp"
Expand Down
Loading