├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── LICENSE.txt ├── Makefile.am ├── NEWS ├── README ├── configure.ac ├── doc ├── Doxyfile.api.in ├── Doxyfile.devel.in ├── Makefile.am └── SparseX_UG.pdf ├── include ├── Makefile.am └── sparsex │ ├── common.h │ ├── config.h.in │ ├── error.h │ ├── internals │ ├── Affinity.hpp │ ├── Allocators.hpp │ ├── Barrier.hpp │ ├── CodeExecutor.hpp │ ├── Compiler.hpp │ ├── Config.hpp.in │ ├── Csr.hpp │ ├── CsrIterator.hpp │ ├── Csx.hpp │ ├── CsxBuild.hpp │ ├── CsxGetSet.hpp │ ├── CsxJit.hpp │ ├── CsxKernels.hpp │ ├── CsxManager.hpp │ ├── CsxSaveRestore.hpp │ ├── CsxSpmv.hpp │ ├── CsxUtil.hpp │ ├── CtlBuilder.hpp │ ├── CtlUtil.hpp │ ├── Delta.hpp │ ├── DynamicArray.hpp │ ├── Element.hpp │ ├── EncodingManager.hpp │ ├── Encodings.hpp │ ├── Facade.hpp │ ├── JitCompiler.hpp │ ├── JitConfig.hpp │ ├── JitUtil.hpp │ ├── Map.hpp │ ├── Mmf.hpp │ ├── Node.hpp │ ├── Rcm.hpp │ ├── Runtime.hpp │ ├── SparseInternal.hpp │ ├── SparseMatrix.hpp │ ├── SparsePartition.hpp │ ├── SpmMt.hpp │ ├── SpmvMethod.hpp │ ├── Statistics.hpp │ ├── TemplateText.hpp │ ├── ThreadPool.hpp │ ├── Timer.hpp │ ├── TimerCollection.hpp │ ├── Types.hpp │ ├── Utility.hpp │ ├── Vector.hpp │ ├── Xform.hpp │ ├── cdecl.h │ ├── futex.h │ ├── logger │ │ ├── Logger.hpp │ │ ├── LoggerUtil.hpp │ │ └── OutputPolicy.hpp │ └── numa_util.h │ ├── matvec.h │ ├── sparsex.h │ ├── timing.h │ ├── types.h │ └── version.h.in ├── m4check ├── ax_check_boost.m4 ├── ax_check_icu.m4 ├── ax_check_llvm.m4 ├── ax_check_mkl.m4 ├── ax_check_prog.m4 ├── ax_compilers.m4 ├── ax_platforms.m4 ├── ax_prog_doxygen.m4 ├── ax_utility.m4 ├── doxygen_rules.am └── verbose_rules.am ├── scripts ├── Makefile.am └── sparsex-config.in ├── src ├── Makefile.am ├── api │ ├── Makefile.am │ ├── common.c │ ├── error.c │ └── matvec.c ├── bench │ ├── Bench.cpp │ ├── Bench.hpp │ ├── BenchUtil.hpp │ ├── Makefile.am │ ├── MklModule.cpp │ ├── MklModule.hpp │ ├── Mmf.hpp │ ├── PoskiModule.cpp │ ├── PoskiModule.hpp │ ├── SparsexModule.cpp │ ├── SparsexModule.hpp │ ├── Timer.cpp │ ├── Timer.hpp │ └── main.cpp ├── examples │ ├── Makefile.am │ ├── advanced_example.c │ ├── csr_example.c │ ├── matrix_caching_example_p1.c │ ├── matrix_caching_example_p2.c │ ├── mmf_example.c │ └── reordering_example.c ├── internals │ ├── Affinity.cpp │ ├── Barrier.cpp │ ├── CodeExecutor.cpp │ ├── CsxBuild.cpp │ ├── CsxKernels.cpp │ ├── CsxSpmv.cpp │ ├── CsxUtil.cpp │ ├── CtlBuilder.cpp │ ├── Encodings.cpp │ ├── Facade.cpp │ ├── JitCompiler.cpp │ ├── JitUtil.cpp │ ├── Makefile.am │ ├── Mmf.cpp │ ├── Node.cpp │ ├── Runtime.cpp │ ├── Statistics.cpp │ ├── TemplateText.cpp │ ├── ThreadPool.cpp │ ├── Timer.cpp │ ├── TimerCollection.cpp │ ├── Vector.cpp │ ├── futex.c │ ├── logger │ │ ├── Logger.cpp │ │ └── OutputPolicy.cpp │ └── numa_util.c └── templates │ ├── Makefile.am │ ├── block_col_one_tmpl.c │ ├── block_col_sym_tmpl.c │ ├── block_col_tmpl.c │ ├── block_row_one_tmpl.c │ ├── block_row_sym_tmpl.c │ ├── block_row_tmpl.c │ ├── csx_spmv_tmpl.c │ ├── csx_sym_spmv_tmpl.c │ ├── delta_sym_tmpl.c │ ├── delta_tmpl.c │ ├── diag_sym_tmpl.c │ ├── diag_tmpl.c │ ├── horiz_sym_tmpl.c │ ├── horiz_tmpl.c │ ├── rdiag_sym_tmpl.c │ ├── rdiag_tmpl.c │ ├── vert_sym_tmpl.c │ └── vert_tmpl.c └── test ├── Makefile.am ├── matrices ├── Makefile.am ├── demopatt.mtx.sorted ├── demopatt.mtx.unsorted ├── symmetric-very-sparse.mtx.sorted ├── symmetric.mtx.sorted ├── test.mtx.sorted ├── test2.mtx.sorted └── test3.mtx.sorted ├── scripts └── test-sparsex.sh.in └── src ├── BinaryTest_p1.cpp ├── BinaryTest_p2.cpp ├── CsxBench.cpp ├── CsxBench.hpp ├── CsxCheck.cpp ├── CsxCheck.hpp ├── DynamicArrayTest.cpp ├── ElementTest.cpp ├── Makefile.am ├── SpmvTest.cpp ├── TimerTest.cpp └── sparsex_test.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.in 3 | *.sorted 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Actively maintained by 2 | 3 | Athena Elafrou athenacslab.ece.ntua.gr 4 | Vasileios Karakasis bkkcslab.ece.ntua.gr 5 | 6 | Past Contributors 7 | 8 | Kornilios Kourtis kkourtcslab.ece.ntua.gr 9 | Thodoris Gountouvas thgoudcslab.ece.ntua.gr 10 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011-2017, Computing Systems Laboratory (CSLab), NTUA. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 3. Neither the name of the Computing Systems Laboratory, NTUA nor the names of 13 | its contributors may be used to endorse or promote products derived from this 14 | software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | ChangeLog v1.1.0 2 | 46c7269 Updated SparseX version in configuration files. 3 | 4f31e92 Updated README. 4 | 39254d0 Re-design of SparseX's JIT component to use LLVM/Clang's MCJIT engine. 5 | e8946ff Moved Linux-based futex wrapper in a seperate C module. 6 | 1e9ad14 Small change in vector API to simplify usage. 7 | e8d17ba Updated testing utility to check y = alpha*A*x. Also fixed FLOPS computation. 8 | 1eef307 Small fix in llvm/clang configuration file. 9 | ead8529 Configuration script improvements. 10 | 11 | ChangeLog v1.0.2 12 | 830f671 Style enhancements. 13 | 939f710 Enhancements in LLVM configure checks. 14 | 290f36f SparseX now supports both clang-llvm-3.0 and clang-llvm-3.5. 15 | 29d9119 Major changes in preprocessing 16 | 208e9cd Minor changes to preprocessing 17 | 80a3aec Preprocessing performance improvements 18 | 282627d Minor preprocessing improvements 19 | 43a42bc Store-forwarding fix for IndexType = int for x86_64 arch. 20 | 590a4bc Small changes to activate move semantics for Element class. 21 | 22 | ChangeLog v1.0.1 23 | a8695fa Support for runtime configuration of the JIT include path. 24 | 1dafcd5 Small fix in benchmarking framework in case the output vector is tuned. 25 | 5b7e4bb Added API functionality to extract the split points of the matrix in a multithreaded execution, which is useful when implementing solvers. 26 | 8240e48 Updated user's guide and unified runtime options for the benchmarking framework (help message is also improved). 27 | e75ea29 Missing header file. 28 | ecd165f Small fixes all over the place. 29 | 35577db Updated Doxyfiles + minor improvement in the examples. 30 | 8f97189 Some aesthetic changes + workaround for Clang 3.0 crash 31 | afd5d73 Small fixes. 32 | 66d4917 Improvements in the auto-configuration process. 33 | ab64ce5 Important fixes. 34 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011-2017, Computing Systems Laboratory (CSLab), NTUA. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 3. Neither the name of the Computing Systems Laboratory, NTUA nor the names of 13 | its contributors may be used to endorse or promote products derived from this 14 | software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- Top level Makefile.am 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All rights reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | ACLOCAL_AMFLAGS = -I m4check 13 | SUBDIRS = include scripts src test 14 | 15 | if SPX_GENERATE_DOC 16 | SUBDIRS += doc 17 | endif 18 | 19 | silent_flag = $(silent_flag_$(V)) 20 | silent_flag_ = $(silent_flag_$(AM_DEFAULT_VERBOSITY)) 21 | silent_flag_0 = --silent 22 | AM_MAKEFLAGS = $(silent_flag) 23 | 24 | dist_noinst_DATA = LICENSE.txt doc/SparseX_UG.pdf 25 | 26 | # Recursively invoke our new and/or redefined targets 27 | doc doc-api doc-devel clean-doc mostlyclean-local: 28 | $(MAKE) $(AM_MAKEFLAGS) -C @dx_docdir@ $@ 29 | 30 | # Always install user guide, whether doxygen documentation is built or not 31 | install-data-local: 32 | @echo -n "Installing user guide... " 33 | @$(MKDIR_P) @docdir@ 34 | @INSTALL_DATA@ $(top_srcdir)/doc/SparseX_UG.pdf @docdir@ && \ 35 | echo "done" || echo "failed" 36 | 37 | uninstall-local: 38 | $(RM) @docdir@/SparseX_UG.pdf 39 | 40 | .PHONY: doc doc-api doc-devel 41 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cslab-ntua/sparsex/7dc4a7988cc7ef0b0e9797f83c95877b2e3432b5/NEWS -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- Necessary rules for auto-generating project's documentation. 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All righrs reserved 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | 13 | include $(top_srcdir)/m4check/doxygen_rules.am 14 | -------------------------------------------------------------------------------- /doc/SparseX_UG.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cslab-ntua/sparsex/7dc4a7988cc7ef0b0e9797f83c95877b2e3432b5/doc/SparseX_UG.pdf -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- SparseX library 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All rights reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | RM = /bin/rm -f 12 | install_data = @INSTALL_DATA@ 13 | 14 | nobase_include_HEADERS = \ 15 | sparsex/common.h \ 16 | sparsex/error.h \ 17 | sparsex/matvec.h \ 18 | sparsex/sparsex.h \ 19 | sparsex/timing.h \ 20 | sparsex/types.h \ 21 | sparsex/internals/cdecl.h \ 22 | sparsex/internals/futex.h \ 23 | sparsex/internals/numa_util.h \ 24 | sparsex/internals/Affinity.hpp \ 25 | sparsex/internals/Allocators.hpp \ 26 | sparsex/internals/Barrier.hpp \ 27 | sparsex/internals/Csr.hpp \ 28 | sparsex/internals/CodeExecutor.hpp \ 29 | sparsex/internals/Csx.hpp \ 30 | sparsex/internals/CsxBuild.hpp \ 31 | sparsex/internals/CsxGetSet.hpp \ 32 | sparsex/internals/CsxJit.hpp \ 33 | sparsex/internals/CsxKernels.hpp \ 34 | sparsex/internals/CsxManager.hpp \ 35 | sparsex/internals/CsxSaveRestore.hpp \ 36 | sparsex/internals/CsxSpmv.hpp \ 37 | sparsex/internals/CsxUtil.hpp \ 38 | sparsex/internals/CtlBuilder.hpp \ 39 | sparsex/internals/CtlUtil.hpp \ 40 | sparsex/internals/Delta.hpp \ 41 | sparsex/internals/DynamicArray.hpp \ 42 | sparsex/internals/Element.hpp \ 43 | sparsex/internals/EncodingManager.hpp \ 44 | sparsex/internals/Encodings.hpp \ 45 | sparsex/internals/Facade.hpp \ 46 | sparsex/internals/JitCompiler.hpp \ 47 | sparsex/internals/JitConfig.hpp \ 48 | sparsex/internals/JitUtil.hpp \ 49 | sparsex/internals/Map.hpp \ 50 | sparsex/internals/Mmf.hpp \ 51 | sparsex/internals/Node.hpp \ 52 | sparsex/internals/Rcm.hpp \ 53 | sparsex/internals/Runtime.hpp \ 54 | sparsex/internals/SparseInternal.hpp \ 55 | sparsex/internals/SparseMatrix.hpp \ 56 | sparsex/internals/SparsePartition.hpp \ 57 | sparsex/internals/SpmMt.hpp \ 58 | sparsex/internals/SpmvMethod.hpp \ 59 | sparsex/internals/Statistics.hpp \ 60 | sparsex/internals/TemplateText.hpp \ 61 | sparsex/internals/ThreadPool.hpp \ 62 | sparsex/internals/Timer.hpp \ 63 | sparsex/internals/TimerCollection.hpp \ 64 | sparsex/internals/Types.hpp \ 65 | sparsex/internals/Utility.hpp \ 66 | sparsex/internals/Vector.hpp \ 67 | sparsex/internals/Xform.hpp \ 68 | sparsex/internals/logger/Logger.hpp \ 69 | sparsex/internals/logger/LoggerUtil.hpp \ 70 | sparsex/internals/logger/OutputPolicy.hpp 71 | 72 | # Fill in the correct paths before installing 73 | install-data-local: 74 | $(SED) -e "/.*#define SPX_JIT_INCLUDE/ s/\".*\"/\"`echo $(includedir) | $(SED) -e 's/\//\\\\\//g'`\"/g; /.*#define SPX_MULT_TEMPLATE_DIR/ s/\".*\"/\"`echo $(datarootdir) | $(SED) -e 's/\//\\\\\//g'`\/sparsex\/templates\"/g" sparsex/internals/Config.hpp > sparsex/internals/Config.hpp.install; \ 75 | test -e $(includedir)/sparsex/internals || \ 76 | $(MKDIR_P) $(includedir)/sparsex/internals; \ 77 | $(install_data) sparsex/internals/Config.hpp.install $(includedir)/sparsex/internals/Config.hpp; \ 78 | $(install_data) sparsex/config.h $(includedir)/sparsex/config.h 79 | 80 | uninstall-local: 81 | $(RM) $(includedir)/sparsex/config.h 82 | $(RM) $(includedir)/sparsex/internals/Config.hpp 83 | -------------------------------------------------------------------------------- /include/sparsex/config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file config.h 11 | * \brief SparseX API configuration 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_CONFIG_H 20 | #define SPARSEX_CONFIG_H 21 | 22 | /** 23 | * SparseX configured index type 24 | */ 25 | #define SPX_INDEX_TYPE @SPX_INDEX_TYPE@ 26 | 27 | /** 28 | * SparseX configured index type 29 | */ 30 | #define SPX_VALUE_TYPE @SPX_VALUE_TYPE@ 31 | 32 | #endif // SPARSEX_CONFIG_H 33 | -------------------------------------------------------------------------------- /include/sparsex/internals/Affinity.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2014, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2007-2011, Kornilios Kourtis 4 | * Copyright (C) 2013-2014, Athena Elafrou 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file Affinity.hpp 12 | * \brief Routine that sets the cpu affinity 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_AFFINITY_HPP 21 | #define SPARSEX_INTERNALS_AFFINITY_HPP 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace sparsex { 28 | namespace runtime { 29 | 30 | void setaffinity_oncpu(unsigned int cpu); 31 | int get_cpu_count(); 32 | 33 | } // end of namespace runtime 34 | } // end of namespace sparsex 35 | 36 | #endif // SPARSEX_INTERNALS_AFFINITY_HPP 37 | -------------------------------------------------------------------------------- /include/sparsex/internals/Barrier.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Barrier.hpp 11 | * \brief A centralized barrier with timeout 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_BARRIER_HPP 20 | #define SPARSEX_INTERNALS_BARRIER_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace sparsex { 27 | namespace runtime { 28 | 29 | #define BARRIER_TIMEOUT 300000 30 | 31 | /* 32 | * In a centralized barrier, every thread spins on a global “sense” flag. A 33 | * global count variable holds the number of threads. The global sense flag 34 | * is initially set to an initial state to indicate that the barrier hasn’t 35 | * been reached. When a thread reaches the barrier, it decrements the global 36 | * count to indicate that it has reached the barrier. The last thread to 37 | * reach the barrier resets count to the number of threads, and toggles the 38 | * global “sense”, which indicates to the other threads spinning (or 39 | * sleeping) that all threads have reached the barrier. At this point, all 40 | * threads stop spinning and continue execution. 41 | */ 42 | void centralized_barrier(int *local_sense, size_t nr_threads); 43 | 44 | } // end of namespace runtime 45 | } // end of namespace sparsex 46 | 47 | #endif // SPARSEX_INTERNALS_BARRIER_HPP 48 | -------------------------------------------------------------------------------- /include/sparsex/internals/CodeExecutor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2017, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file CodeExecutor.cpp 11 | * \brief Component that dynamically loads a compiled module in memory for 12 | execution based on LLVM. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2017 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_CODE_EXECUTOR_HPP 21 | #define SPARSEX_INTERNALS_CODE_EXECUTOR_HPP 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | namespace sparsex { 31 | namespace jit { 32 | 33 | // Singleton wrapper to an LLVM execution engine 34 | class CodeExecutor { 35 | public: 36 | 37 | static CodeExecutor &GetInstance() 38 | { 39 | // C++11 mandates that the initializer for a local static variable is 40 | // only run once, even in the presence of concurrency. So, this code 41 | // is thread-safe. 42 | static CodeExecutor instance; 43 | return instance; 44 | } 45 | 46 | ~CodeExecutor(); 47 | // Assumes the given module has been verified 48 | void AddModule(unique_ptr module); 49 | void RemoveModule(llvm::Module *module); 50 | uint64_t GetFnAddress(const string fn_name); 51 | 52 | private: 53 | llvm::EngineBuilder *builder_; 54 | llvm::ExecutionEngine *engine_; 55 | 56 | CodeExecutor(); 57 | CodeExecutor(const CodeExecutor &) = delete; // Do not implement 58 | void operator=(const CodeExecutor &) = delete; // Do not implement 59 | }; 60 | 61 | } // end of namespace jit 62 | } // end of namespace sparsex 63 | 64 | #endif // SPARSEX_INTERNALS_CODE_EXECUTOR_HPP 65 | -------------------------------------------------------------------------------- /include/sparsex/internals/Compiler.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Compiler.hpp 11 | * \brief Wrapper of a Clang compiler instance. Responsible for generating LLVM 12 | * IR code from C99 source 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_COMPILER_HPP 21 | #define SPARSEX_INTERNALS_COMPILER_HPP 22 | 23 | #include 24 | #if CLANG_VERSION_MAJOR == 3 25 | # if CLANG_VERSION_MINOR == 0 26 | # include 27 | # include 28 | # elif CLANG_VERSION_MINOR == 5 29 | # include 30 | # endif 31 | #endif 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | using namespace clang; 38 | using namespace llvm; 39 | using namespace std; 40 | 41 | namespace sparsex { 42 | namespace jit { 43 | 44 | class ClangCompiler 45 | { 46 | public: 47 | enum Options { 48 | IncludePathSystem, 49 | IncludePathUser 50 | }; 51 | 52 | ClangCompiler(); 53 | 54 | ~ClangCompiler() { 55 | // Take back the ownership of the invocation so as to avoid double 56 | // delete() corruption; the invocation will be released from our dtor 57 | //compiler_->takeInvocation(); 58 | 59 | // Just let CompilerInvocation object be released through 60 | // CompilerInstance 61 | }; 62 | 63 | llvm::Module *Compile(const string &source, LLVMContext *context) const; 64 | 65 | void KeepTemporaries(bool keep) 66 | { 67 | keep_temporaries_ = keep; 68 | } 69 | 70 | void SetLogStream(ostream *log) 71 | { 72 | assert(log && "passed ostream is NULL"); 73 | log_stream_ = log; 74 | } 75 | 76 | bool DebugMode() 77 | { 78 | return debug_mode_; 79 | } 80 | 81 | void SetDebugMode(bool debug) 82 | { 83 | debug_mode_ = debug; 84 | SetCodeGenOptions(); 85 | } 86 | 87 | void AddIncludeSearchPath(const string &inc_path, Options type); 88 | // { 89 | // HeaderSearchOptions &header_search = 90 | // invocation_->getHeaderSearchOpts(); 91 | 92 | // // Add path both as a quoted and angled include 93 | // header_search.AddPath(path, frontend::Quoted, 94 | // true /* user supplied */, false, false); 95 | // header_search.AddPath(path, frontend::Angled, 96 | // true /* user supplied */, false, false); 97 | // } 98 | 99 | private: 100 | // Set up the code generation options depending on debug mode 101 | void SetCodeGenOptions(); 102 | CompilerInvocation *invocation_; 103 | // OwningPtr compiler_; 104 | CompilerInstance *compiler_; 105 | bool keep_temporaries_; 106 | bool debug_mode_; 107 | ostream *log_stream_; 108 | }; 109 | 110 | } // end of namespace jit 111 | } // end of namespace sparsex 112 | 113 | #endif // SPARSEX_INTERNALS_COMPILER_HPP 114 | -------------------------------------------------------------------------------- /include/sparsex/internals/Config.hpp.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Config.hpp 11 | * \brief SparseX system configuration 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_CONFIG_HPP 20 | #define SPARSEX_INTERNALS_CONFIG_HPP 21 | 22 | #define SPX_JIT_INCLUDE "@abs_top_srcdir@/include:@abs_top_builddir@/include" 23 | #define SPX_MULT_TEMPLATE_DIR "@abs_top_srcdir@/src/templates" 24 | #define SPX_USE_NUMA @SPX_USE_NUMA@ 25 | #define CLANG_INC_SEARCH_PATH "@CLANG_INC_SEARCH_PATH@" 26 | 27 | #endif // SPARSEX_INTERNALS_CONFIG_HPP 28 | -------------------------------------------------------------------------------- /include/sparsex/internals/Csx.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * Copyright (C) 2011-2012, Theodoros Gkountouvas 6 | * Copyright (C) 2013, Athena Elafrou 7 | * All rights reserved. 8 | * 9 | * This file is distributed under the BSD License. See LICENSE.txt for details. 10 | */ 11 | 12 | /** 13 | * \file Csx.hpp 14 | * \brief The CSX data structure (C front-end) 15 | * 16 | * \author Computing Systems Laboratory (CSLab), NTUA 17 | * \date 2011–2014 18 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 19 | * for details. 20 | */ 21 | 22 | #ifndef SPARSEX_INTERNALS_CSX_HPP 23 | #define SPARSEX_INTERNALS_CSX_HPP 24 | 25 | #include 26 | #include 27 | 28 | ///< CSX matrix format 29 | typedef struct { 30 | spx_index_t rowptr; /* rowptr is the index in csx->ctl of 31 | the first element of row i */ 32 | spx_index_t valptr; /* valptr is the index in csx->values of 33 | the first element of row i */ 34 | spx_index_t span; 35 | } row_info_t; 36 | 37 | typedef struct { 38 | spx_value_t *values; 39 | uint8_t *ctl; 40 | spx_index_t nnz; 41 | spx_index_t ncols; 42 | spx_index_t nrows; 43 | spx_index_t ctl_size; 44 | spx_index_t row_start; 45 | uint8_t row_jumps; 46 | long id_map[CTL_PATTERNS_MAX]; 47 | row_info_t *rows_info; 48 | } csx_matrix_t; 49 | 50 | typedef struct { 51 | csx_matrix_t *lower_matrix; 52 | spx_value_t *dvalues; 53 | } csx_sym_matrix_t; 54 | 55 | #ifdef __cplusplus 56 | // C++ only 57 | 58 | namespace sparsex { 59 | namespace csx { 60 | 61 | // FIXME: members of CsxMatrix MUST have the same order with csx_matrix_t 62 | // This is error-prone with explicit casts between the two types 63 | template 64 | struct CsxMatrix { 65 | ValueType *values; 66 | uint8_t *ctl; 67 | IndexType nnz; 68 | IndexType ncols; 69 | IndexType nrows; 70 | IndexType ctl_size; 71 | IndexType row_start; 72 | uint8_t row_jumps; 73 | long id_map[CTL_PATTERNS_MAX]; 74 | row_info_t *rows_info; 75 | }; 76 | 77 | template 78 | struct CsxSymMatrix { 79 | CsxMatrix *lower_matrix; 80 | ValueType *dvalues; 81 | }; 82 | 83 | } // end of namepsace csx 84 | } // end of namepsace sparsex 85 | 86 | #endif 87 | 88 | #endif // SPARSEX_INTERNALS_CSX_HPP 89 | -------------------------------------------------------------------------------- /include/sparsex/internals/CsxKernels.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2011-2012, Vasileios Karakasis 4 | * Copyright (C) 2013-2014, Athena Elafrou 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file CsxKernels.hpp 12 | * \brief Multithreaded SpMV kernels 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_CSX_KERNELS_HPP 21 | #define SPARSEX_INTERNALS_CSX_KERNELS_HPP 22 | 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #endif 34 | 35 | SPX_BEGIN_C_DECLS__ 36 | 37 | void MatVecMult(const spm_mt_t *spm_mt, const vector_t *x, 38 | spx_value_t alpha, vector_t *y); 39 | void MatVecMult_sym(const spm_mt_t *spm_mt, const vector_t *x, 40 | spx_value_t alpha, vector_t *y); 41 | void MatVecKernel(const spm_mt_t *spm_mt, const vector_t *x, 42 | spx_value_t alpha, vector_t *y, spx_value_t beta); 43 | void MatVecKernel_sym(const spm_mt_t *spm_mt, const vector_t *x, 44 | spx_value_t alpha, vector_t *y, spx_value_t beta); 45 | 46 | SPX_END_C_DECLS__ 47 | 48 | #endif // SPARSEX_INTERNALS_CSX_KERNELS_HPP 49 | -------------------------------------------------------------------------------- /include/sparsex/internals/CsxSpmv.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2012-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file CsxSpmv.hpp 11 | * \brief Thread-level SpMV routines 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_CSX_SPMV_HPP 20 | #define SPARSEX_INTERNALS_CSX_SPMV_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace sparsex { 28 | 29 | void do_mv_thread(void *args); 30 | void do_mv_sym_thread(void *args); 31 | void do_kernel_thread(void *params); 32 | void do_kernel_sym_thread(void *args); 33 | 34 | } // end of namespace sparsex 35 | 36 | #endif // SPARSEX_INTERNALS_CSX_SPMV_HPP 37 | -------------------------------------------------------------------------------- /include/sparsex/internals/CtlBuilder.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file CtlBuilder.hpp 11 | * \brief Utility class for building the CSX's ctl structure 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_CTL_BUILDER_HPP 20 | #define SPARSEX_INTERNALS_CTL_BUILDER_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace sparsex::utilities; 29 | 30 | namespace sparsex { 31 | namespace csx { 32 | 33 | class CtlBuilder 34 | { 35 | public: 36 | CtlBuilder(size_t size_hint) 37 | : ctl_da_(CtlDynamicArray(size_hint)) 38 | { } 39 | 40 | size_t GetCtlSize() const 41 | { 42 | return ctl_da_.GetSize(); 43 | } 44 | 45 | uint8_t *Finalize() 46 | { 47 | // ctl_da_.ShrinkToFit(); 48 | return ctl_da_.TakeElems(); 49 | } 50 | 51 | void AppendCtlHead(bool nr, size_t rowjmp, uint8_t id, uint8_t size, 52 | size_t ucol, size_t ucol_size, bool full_colind); 53 | void AppendVariableInt(unsigned long val); 54 | void AppendFixedInt(unsigned long val, size_t nr_bytes); 55 | 56 | private: 57 | void AlignCtl(size_t boundary); 58 | 59 | #if SPX_USE_NUMA 60 | typedef DynamicArray > 61 | CtlDynamicArray; 62 | #else 63 | typedef DynamicArray CtlDynamicArray; 64 | #endif 65 | 66 | CtlDynamicArray ctl_da_; 67 | }; 68 | 69 | } // end of namespace csx 70 | } // end of namespace sparsex 71 | 72 | #endif // SPARSEX_INTERNALS_CTL_BUILDER_HPP 73 | -------------------------------------------------------------------------------- /include/sparsex/internals/CtlUtil.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2011, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file CtlUtil.hpp 12 | * \brief Definitions and utilities for the ctl byte array of CSX 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_CTL_UTIL_HPP 21 | #define SPARSEX_INTERNALS_CTL_UTIL_HPP 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | SPX_BEGIN_C_DECLS__ 28 | 29 | /* 30 | * Bit functions 31 | */ 32 | static inline void set_bit(uint8_t *byte, int bit) 33 | { 34 | assert(bit >= 0); 35 | assert(bit < 8); 36 | *byte |= (1<= 0); 42 | assert(bit < 8); 43 | return (*byte & (1< arbitrary patterns 57 | // row jmp 58 | // (if enabled) 59 | #define CTL_NR_BIT 7 60 | #define CTL_RJMP_BIT 6 61 | #define CTL_PATTERNS_MAX ((1 << CTL_RJMP_BIT) - 1) 62 | 63 | // size is 8 bits: 0..255 64 | #define CTL_SIZE_MAX ((1<<8) - 1) 65 | 66 | #define CTL_PATTERN_MASK ~(1< 24 | 25 | namespace sparsex { 26 | namespace csx { 27 | 28 | typedef union { 29 | uint8_t d8; 30 | uint16_t d16; 31 | uint32_t d32; 32 | uint64_t d64; 33 | } DeltaType; 34 | 35 | inline size_t GetDeltaSize(size_t val) 36 | { 37 | DeltaType du; 38 | if ((du.d8 = val) == val) 39 | return sizeof(du.d8); 40 | 41 | if ((du.d16 = val) == val) 42 | return sizeof(du.d16); 43 | 44 | if ((du.d32 = val) == val) 45 | return sizeof(du.d32); 46 | 47 | return sizeof(du.d64); 48 | } 49 | 50 | } // end of namespace csx 51 | } // end of namespace sparsex 52 | 53 | #endif // SPARSEX_INTERNALS_DELTA_HPP 54 | -------------------------------------------------------------------------------- /include/sparsex/internals/Facade.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Facade.hpp 11 | * \brief Wrappers of the SparseMatrix routines 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_FACADE_HPP 20 | #define SPARSEX_INTERNALS_FACADE_HPP 21 | 22 | #include 23 | #include 24 | 25 | SPX_BEGIN_C_DECLS__ 26 | 27 | /** 28 | * SparseMatrix wrapper functions. 29 | */ 30 | void *CreateCSR(const spx_index_t *rowptr, const spx_index_t *colind, 31 | const spx_value_t *values, spx_index_t nr_rows, 32 | spx_index_t nr_cols, int zero_based); 33 | void *CreateMMF(const char *filename, 34 | spx_index_t *nr_rows, spx_index_t *nr_cols, spx_index_t *nnz); 35 | void *ReorderCSR(void *matrix, spx_index_t **permutation); 36 | void *ReorderMMF(void *matrix, spx_index_t **permutation); 37 | void *TuneCSR(void *matrix, int *symmetric); 38 | void *TuneMMF(void *matrix, int *symmetric); 39 | void DestroyCSR(void *matrix); 40 | void DestroyMMF(void *matrix); 41 | void SaveTuned(void *matrix, const char *filename, spx_index_t *permutation); 42 | void *LoadTuned(const char *filename, 43 | spx_index_t *nr_rows, spx_index_t *nr_cols, 44 | spx_index_t *nnz, spx_index_t **permutation); 45 | int GetValue(void *matrix, 46 | spx_index_t row, spx_index_t col, spx_value_t *value); 47 | int SetValue(void *matrix, spx_index_t row, spx_index_t col, spx_value_t value); 48 | void DestroyCsx(void *matrix); 49 | void SetPropertyByMnemonic(const char *key, const char *value); 50 | void SetPropertiesFromEnv(); 51 | void GetNodes(int *nodes); 52 | void CreatePool(); 53 | 54 | SPX_END_C_DECLS__ 55 | 56 | #endif // SPARSEX_INTERNALS_FACADE_HPP 57 | -------------------------------------------------------------------------------- /include/sparsex/internals/JitCompiler.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2017, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file JitCompiler.hpp 11 | * \brief Wrapper of a Clang compiler instance. Responsible for generating LLVM 12 | * IR code from C99 source 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_JIT_COMPILER_HPP 21 | #define SPARSEX_INTERNALS_JIT_COMPILER_HPP 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include 43 | #include 44 | 45 | using namespace std; 46 | 47 | namespace sparsex { 48 | namespace jit { 49 | 50 | class ClangCompiler 51 | { 52 | public: 53 | enum Options { 54 | IncludePathSystem, 55 | IncludePathUser 56 | }; 57 | 58 | ClangCompiler(); 59 | ~ClangCompiler() {} 60 | 61 | unique_ptr Compile(const string &source) const; 62 | 63 | void KeepTemporaries(bool keep) 64 | { 65 | keep_temporaries_ = keep; 66 | } 67 | 68 | void SetLogStream(ostream *log) 69 | { 70 | assert(log && "passed ostream is NULL"); 71 | } 72 | 73 | bool DebugMode() 74 | { 75 | return debug_mode_; 76 | } 77 | 78 | void SetDebugMode(bool debug) 79 | { 80 | debug_mode_ = debug; 81 | } 82 | 83 | void AddIncludeSearchPath(const string &inc_path, Options type); 84 | 85 | private: 86 | shared_ptr invocation_; 87 | unique_ptr instance_; 88 | bool keep_temporaries_; 89 | bool debug_mode_; 90 | }; 91 | 92 | } // end of namespace jit 93 | } // end of namespace sparsex 94 | 95 | #endif // SPARSEX_INTERNALS_JIT_COMPILER_HPP 96 | -------------------------------------------------------------------------------- /include/sparsex/internals/JitUtil.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file JitUtil.hpp 11 | * \brief Jit-related utility functions 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_JIT_UTIL_HPP 20 | #define SPARSEX_INTERNALS_JIT_UTIL_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | namespace sparsex { 31 | namespace jit { 32 | 33 | string SourceFromFile(const char *filename); 34 | string SourceFromFile(const string &filename); 35 | void SourceToFile(const char *filename, const string &source); 36 | void SourceToFile(const string &filename, const string &source); 37 | const char *UniqueFilename(string &tmpl); 38 | void RemoveFile(const char *path); 39 | string Tabify(int num); 40 | 41 | template 42 | string Stringify(const T& t) 43 | { 44 | stringstream ss; 45 | ss << t; 46 | return ss.str(); 47 | } 48 | 49 | } // end of namespace jit 50 | } // end of namespace sparsex 51 | 52 | #endif // SPARSEX_INTERNALS_JIT_UTIL_HPP 53 | -------------------------------------------------------------------------------- /include/sparsex/internals/Map.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2012, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2011-2012, Theodoros Gkountouvas 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Map.hpp 11 | * \brief Map used for symmetric sparse matrices 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_MAP_HPP 20 | #define SPARSEX_INTERNALS_MAP_HPP 21 | 22 | ///> The definition of map used for symmetric sparse matrices. 23 | typedef struct map { 24 | unsigned int length; 25 | unsigned int *cpus; 26 | unsigned int *elems_pos; 27 | } map_t; 28 | 29 | #endif // SPARSEX_INTERNALS_MAP_HPP 30 | -------------------------------------------------------------------------------- /include/sparsex/internals/Node.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2009-2012, Vasileios Karakasis 5 | * Copyright (C) 2010-2012, Theodoros Gkountouvas 6 | * All rights reserved. 7 | * 8 | * This file is distributed under the BSD License. See LICENSE.txt for details. 9 | */ 10 | 11 | /** 12 | * \file Node.hpp 13 | * \brief Node class 14 | * 15 | * \author Computing Systems Laboratory (CSLab), NTUA 16 | * \date 2011–2014 17 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 18 | * for details. 19 | */ 20 | 21 | #ifndef SPARSEX_INTERNALS_NODE_HPP 22 | #define SPARSEX_INTERNALS_NODE_HPP 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace std; 31 | 32 | namespace sparsex { 33 | namespace csx { 34 | 35 | /** 36 | * Keeps data of an encoding sequence. 37 | */ 38 | class Node { 39 | public: 40 | Node(uint32_t depth); 41 | ~Node() {} 42 | 43 | void PrintNode(); 44 | 45 | /** 46 | * Ignore the type for the encoding sequence examined. 47 | * 48 | * @param type type which is ignored. 49 | */ 50 | void Ignore(Encoding::Type type); 51 | 52 | /** 53 | * Copies a node to a new one and inserts an extra type in the end of the 54 | * encoding sequence. 55 | * 56 | * @param type type which is inserted in the end. 57 | * @param deltas deltas corresponding to type inserted. 58 | */ 59 | Node MakeChild(Encoding::Type type, set deltas); 60 | 61 | private: 62 | uint32_t depth_; 63 | map > deltas_path_; 64 | Encoding::Type *type_path_; 65 | Encoding::Type *type_ignore_; 66 | template 67 | friend class EncodingManager; 68 | }; 69 | 70 | } // end of namespace csx 71 | } // end of namespace sparsex 72 | 73 | #endif // SPARSEX_INTERNALS_NODE_HPP 74 | -------------------------------------------------------------------------------- /include/sparsex/internals/SpmMt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2013, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2007-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2012, Vasileios Karakasis 5 | * Copyright (C) 2011-2012, Theodoros Gkountouvas 6 | * Copyright (C) 2013, Athena Elafrou 7 | * All rights reserved. 8 | * 9 | * This file is distributed under the BSD License. See LICENSE.txt for details. 10 | */ 11 | 12 | /** 13 | * \file SpmMt.hpp 14 | * 15 | * \author Computing Systems Laboratory (CSLab), NTUA 16 | * \date 2011–2014 17 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 18 | * for details. 19 | */ 20 | 21 | #ifndef SPARSEX_INTERNALS_SPM_MT_HPP 22 | #define SPARSEX_INTERNALS_SPM_MT_HPP 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | struct spm_mt_thread { 32 | spmv_fn_t spmv_fn; 33 | void *csx; 34 | void *data; 35 | map_t *map; 36 | // uint64_t *col_map; 37 | const vector_t *x; 38 | vector_t *y; 39 | int sense; 40 | double alpha; 41 | double beta; 42 | double secs; 43 | unsigned int cpu; 44 | unsigned int id; 45 | unsigned int node; 46 | unsigned int row_start; 47 | unsigned int end; 48 | unsigned int nr_rows; 49 | size_t size_assigned; 50 | }; 51 | typedef struct spm_mt_thread spm_mt_thread_t; 52 | 53 | struct spm_mt { 54 | spm_mt_thread_t *spm_threads; 55 | vector_t **local_buffers; 56 | unsigned int nr_threads; 57 | bool symmetric; 58 | #if SPX_USE_NUMA 59 | bool interleaved; 60 | #endif 61 | }; 62 | 63 | typedef struct spm_mt spm_mt_t; 64 | 65 | #endif // SPARSEX_INTERNALS_SPM_MT_HPP 66 | -------------------------------------------------------------------------------- /include/sparsex/internals/SpmvMethod.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2012, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2007-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2012, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file SpmvMethod.hpp 12 | * \brief SpMV function types 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_SPMV_METHOD_H 21 | #define SPARSEX_INTERNALS_SPMV_METHOD_H 22 | 23 | #include 24 | 25 | typedef void (*spmv_fn_t)(const void *matrix, const vector_t *in, vector_t *out, 26 | spx_value_t scale_f, vector_t *local_buff); 27 | 28 | #endif // SPARSEX_INTERNALS_SPMV_METHOD_H 29 | -------------------------------------------------------------------------------- /include/sparsex/internals/TemplateText.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file TemplateText.hpp 11 | * \brief Class for manipulating template texts 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_TEMPLATE_TEXT_HPP 20 | #define SPARSEX_INTERNALS_TEMPLATE_TEXT_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace sparsex { 28 | namespace jit { 29 | 30 | class TemplateText 31 | { 32 | public: 33 | TemplateText(string text); 34 | 35 | const string &GetTemplate() const 36 | { 37 | return const_cast(template_text_); 38 | } 39 | 40 | void SetTemplate(string text); 41 | string Substitute(const std::map &values); 42 | 43 | private: 44 | void ReplacePlaceholders(); 45 | string DoSubstitute(); 46 | string template_text_; 47 | std::map placeholders_; 48 | boost::regex placeholder_pattern_; 49 | 50 | class TextReplacer { 51 | public: 52 | TextReplacer(TemplateText *outer) 53 | : outer_(outer) {} 54 | 55 | string operator()(const boost::match_results &match) 56 | { 57 | string key(match[1].first, match[1].second); 58 | return outer_->placeholders_[key]; 59 | } 60 | 61 | private: 62 | TemplateText *outer_; 63 | }; 64 | }; 65 | 66 | } // end of namespace jit 67 | } // end of namespace sparsex 68 | 69 | #endif // SPARSEX_INTERNALS_TEMPLATE_TEXT_HPP 70 | -------------------------------------------------------------------------------- /include/sparsex/internals/ThreadPool.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file ThreadPool.hpp 11 | * \brief Thread management in SparseX 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_THREAD_POOL_HPP 20 | #define SPARSEX_INTERNALS_THREAD_POOL_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace sparsex { 31 | namespace runtime { 32 | 33 | enum Op { 34 | IDLE = -1, 35 | SPMV_MULT, 36 | SPMV_MULT_SYM, 37 | SPMV_KERNEL, 38 | SPMV_KERNEL_SYM 39 | }; 40 | 41 | class ThreadPool; 42 | 43 | class Worker 44 | { 45 | friend class ThreadPool; 46 | 47 | public: 48 | Worker() : sense_(1), job_(IDLE) {} 49 | 50 | void SetId(size_t id) 51 | { 52 | id_ = id; 53 | } 54 | 55 | void SetJob(int job_id) 56 | { 57 | job_ = job_id; 58 | } 59 | 60 | void SetData(void *data) 61 | { 62 | data_ = data; 63 | } 64 | 65 | int GetJob() 66 | { 67 | return job_; 68 | } 69 | 70 | int *GetSense() 71 | { 72 | return &sense_; 73 | } 74 | 75 | private: 76 | size_t id_; 77 | int sense_; 78 | int job_; 79 | // use unique_ptr when C++14 available (make_unique) 80 | std::shared_ptr thread_; 81 | void *data_; 82 | }; 83 | 84 | class ThreadPool 85 | { 86 | public: 87 | static ThreadPool &GetInstance() 88 | { 89 | static ThreadPool instance; 90 | return instance; 91 | } 92 | 93 | void InitThreads(size_t nr_threads); 94 | void Run(Worker &worker); 95 | void SetKernel(int kernel_id); 96 | 97 | void SetWorkerData(size_t worker_id, void *data) 98 | { 99 | workers_[worker_id].SetData(data); 100 | } 101 | 102 | int *GetSense() 103 | { 104 | return &sense_; 105 | } 106 | 107 | size_t GetSize() 108 | { 109 | return size_; 110 | } 111 | 112 | private: 113 | int sense_; 114 | size_t size_; 115 | atomic_bool work_done_; 116 | vector workers_; 117 | 118 | ThreadPool() : sense_(1), size_(0), work_done_(false) {} 119 | ThreadPool(ThreadPool const&); 120 | ~ThreadPool(); 121 | ThreadPool& operator=(ThreadPool const&); 122 | }; 123 | 124 | } // end of namespace runtime 125 | } // end of namespace sparsex 126 | 127 | #endif // SPARSEX_INTERNALS_THREAD_POOL_HPP 128 | -------------------------------------------------------------------------------- /include/sparsex/internals/Timer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2013, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2010-2012, Vasileios Karakasis 4 | * Copyright (C) 2012-2013, Athena Elafrou 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file Timer.hpp 12 | * \brief Timing utilities 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_TIMER_HPP 21 | #define SPARSEX_INTERNALS_TIMER_HPP 22 | 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | 28 | namespace sparsex { 29 | namespace timing { 30 | 31 | class Timer 32 | { 33 | public: 34 | 35 | Timer() 36 | : description_(), 37 | elapsed_time_(), 38 | timestamp_() 39 | { 40 | Clear(); 41 | } 42 | 43 | Timer(string desc) 44 | : description_(desc), 45 | elapsed_time_(), 46 | timestamp_() 47 | { 48 | Clear(); 49 | } 50 | 51 | Timer(const char *desc, const char *desc2) 52 | : description_((string) desc), 53 | elapsed_time_(), 54 | timestamp_() 55 | { 56 | Clear(); 57 | } 58 | 59 | ~Timer() {} 60 | 61 | void Start(); 62 | void Pause(); 63 | void Stop(); 64 | void Clear(); 65 | double ElapsedTime(); 66 | 67 | void SetDescription(const char *desc) 68 | { 69 | description_ = (string) desc; 70 | } 71 | 72 | void SetDescription(string desc) 73 | { 74 | description_ = desc; 75 | } 76 | 77 | string GetDescription() 78 | { 79 | return description_; 80 | } 81 | 82 | private: 83 | string description_; 84 | struct timeval elapsed_time_; 85 | struct timeval timestamp_; 86 | }; 87 | 88 | } // end of namespace timing 89 | } // end of namespace sparsex 90 | 91 | #endif // SPARSEX_INTERNALS_TIMER_HPP 92 | -------------------------------------------------------------------------------- /include/sparsex/internals/TimerCollection.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013 Athena Elafrou 4 | * Copyright (C) 2014 Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file TimerCollection.hpp 12 | * \brief A collection of arbitrary timers 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_TIMING_FRAMEWORK_HPP 21 | #define SPARSEX_INTERNALS_TIMING_FRAMEWORK_HPP 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace std; 28 | 29 | namespace sparsex { 30 | namespace timing { 31 | 32 | class TimerCollection 33 | { 34 | public: 35 | TimerCollection() {} 36 | 37 | void CreateTimer(const char *name, const char *description) 38 | { 39 | timers_.emplace(name, Timer(description)); 40 | } 41 | 42 | void StartTimer(const char *name) 43 | { 44 | timers_[name].Start(); 45 | } 46 | 47 | void PauseTimer(const char *name) 48 | { 49 | timers_[name].Pause(); 50 | } 51 | 52 | void PrintAllTimers(ostream &os) const; 53 | 54 | private: 55 | boost::unordered_map timers_; 56 | TimerCollection(const TimerCollection &); // Do not implement 57 | TimerCollection &operator=(const TimerCollection &); // Do not implement 58 | }; 59 | 60 | } // end of namespace timing 61 | } // end of namespace sparsex 62 | 63 | #endif // SPARSEX_INTERNALS_TIMING_FRAMEWORK_HPP 64 | -------------------------------------------------------------------------------- /include/sparsex/internals/Types.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2014, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Types.hpp 11 | * \brief Wrap API's types.h and promote user supplied types to our internals 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_TYPES_HPP 20 | #define SPARSEX_INTERNALS_TYPES_HPP 21 | 22 | #include 23 | #include 24 | 25 | // Index type should be promoted to unsigned internally 26 | typedef boost::make_unsigned::type spx_uindex_t; 27 | 28 | #endif // SPARSEX_INTERNALS_TYPES_HPP 29 | -------------------------------------------------------------------------------- /include/sparsex/internals/Utility.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Utility.hpp 11 | * \brief Several generic utility functions 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_UTILITY_HPP 20 | #define SPARSEX_INTERNALS_UTILITY_HPP 21 | 22 | #include 23 | 24 | using namespace std; 25 | 26 | namespace sparsex { 27 | namespace utilities { 28 | 29 | template 30 | struct math_impl 31 | { 32 | template 33 | static T do_gcd(T a, T b); 34 | 35 | template 36 | static T do_abs(T a); 37 | 38 | template 39 | static T do_iceil(T a, T b); 40 | }; 41 | 42 | template 43 | T gcd(T a, T b) 44 | { 45 | return math_impl::value>::do_gcd(a, b); 46 | } 47 | 48 | // Integer ceiling 49 | template 50 | T iceil(T a, T b) 51 | { 52 | return math_impl::value>::do_iceil(a, b); 53 | } 54 | 55 | template 56 | T abs(T a) 57 | { 58 | return math_impl::value>::do_abs(a); 59 | } 60 | 61 | template 62 | T lcm(T a, T b) 63 | { 64 | return abs(a*b) / gcd(a, b); 65 | } 66 | 67 | template<> 68 | struct math_impl 69 | { 70 | template 71 | static T do_gcd(T a, T b) 72 | { 73 | while (b) { 74 | T t = b; 75 | b = a % b; 76 | a = t; 77 | } 78 | 79 | return a; 80 | } 81 | 82 | template 83 | static T do_iceil(T a, T b) 84 | { 85 | return a / b + (a % b != 0); 86 | } 87 | 88 | template 89 | static T do_abs(T a) 90 | { 91 | return (a < 0) ? -a : a; 92 | } 93 | }; 94 | 95 | template 96 | struct iterator_checker 97 | { 98 | template 99 | static void do_check(const Iterator &) {} 100 | }; 101 | 102 | template 103 | void check_iterator(const Iterator &i) 104 | { 105 | iterator_checker::value>::do_check(i); 106 | } 107 | 108 | template<> 109 | struct iterator_checker 110 | { 111 | template 112 | static void do_check(const Iterator &i) 113 | { 114 | if (!i) 115 | throw invalid_argument("invalid iterator"); 116 | } 117 | }; 118 | 119 | } // end of namespace utilities 120 | } // end of namespace sparsex 121 | 122 | #endif // SPARSEX_INTERNALS_UTILITY_HPP 123 | -------------------------------------------------------------------------------- /include/sparsex/internals/Vector.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2009-2012, Vasileios Karakasis 5 | * Copyright (C) 2012-2014, Athena Elafrou 6 | * All rights reserved. 7 | * 8 | * This file is distributed under the BSD License. See LICENSE.txt for details. 9 | */ 10 | 11 | /** 12 | * \file Vector.hpp 13 | * \brief Vector interface 14 | * 15 | * \author Computing Systems Laboratory (CSLab), NTUA 16 | * \date 2011–2014 17 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 18 | * for details. 19 | */ 20 | 21 | #ifndef SPARSEX_INTERNALS_VECTOR_HPP 22 | #define SPARSEX_INTERNALS_VECTOR_HPP 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | SPX_BEGIN_C_DECLS__ 29 | 30 | struct vector_struct { 31 | spx_value_t *elements; 32 | size_t size; 33 | int alloc_type; 34 | int vec_mode; 35 | }; 36 | 37 | typedef struct vector_struct vector_t; 38 | 39 | vector_t *VecCreate(size_t size); 40 | vector_t *VecCreateOnnode(size_t size, int node); 41 | vector_t *VecCreateInterleaved(size_t size, size_t nr_parts, size_t *parts, 42 | int *nodes, spx_index_t *row_start, 43 | spx_index_t *row_end); 44 | vector_t *VecCreateFromBuff(spx_value_t *buff, size_t size, size_t nr_parts, 45 | int *cpus, spx_index_t *row_start, 46 | spx_index_t *row_end, int mode); 47 | vector_t *VecCreateRandom(size_t size); 48 | vector_t *VecCreateRandomInterleaved(size_t size, size_t nr_parts, 49 | size_t *parts, int *nodes, 50 | spx_index_t *row_start, 51 | spx_index_t *row_end); 52 | void VecDestroy(vector_t *v); 53 | void VecInit(vector_t *v, spx_value_t val); 54 | void VecInitPart(vector_t *v, spx_value_t val, spx_index_t start, 55 | spx_index_t end); 56 | void VecInitFromMap(vector_t **v, spx_value_t val, map_t *map); 57 | void VecInitRandRange(vector_t *v, spx_value_t max, spx_value_t min); 58 | void VecInitRandRangePart(vector_t *v, spx_index_t start, spx_index_t end, 59 | spx_value_t max, spx_value_t min); 60 | void VecSetEntry(vector_t *v, spx_index_t idx, spx_value_t val); 61 | void VecAdd(vector_t *v1, vector_t *v2, vector_t *v3); 62 | void VecAddPart(vector_t *v1, vector_t *v2, vector_t *v3, spx_index_t start, 63 | spx_index_t end); 64 | void VecAddFromMap(vector_t *v1, vector_t **v2, vector_t *v3, map_t *map); 65 | void VecSub(vector_t *v1, vector_t *v2, vector_t *v3); 66 | void VecSubPart(vector_t *v1, vector_t *v2, vector_t *v3, spx_index_t start, 67 | spx_index_t end); 68 | spx_value_t VecMult(const vector_t *v1, const vector_t *v2); 69 | spx_value_t VecMultPart(const vector_t *v1, const vector_t *v2, 70 | spx_index_t start, spx_index_t end); 71 | void VecScale(vector_t *v1, vector_t *v2, spx_value_t num); 72 | void VecScalePart(vector_t *v1, vector_t *v2, spx_value_t num, 73 | spx_index_t start, spx_index_t end); 74 | void VecScaleAdd(vector_t *v1, vector_t *v2, vector_t *v3, spx_value_t num); 75 | void VecScaleAddPart(vector_t *v1, vector_t *v2, vector_t *v3, spx_value_t num, 76 | spx_index_t start, spx_index_t end); 77 | void VecCopy(const vector_t *v1, vector_t *v2); 78 | int VecCompare(const vector_t *v1, const vector_t *v2); 79 | void VecPrint(const vector_t *v); 80 | 81 | SPX_END_C_DECLS__ 82 | 83 | #endif // SPARSEX_INTERNALS_VECTOR_HPP 84 | -------------------------------------------------------------------------------- /include/sparsex/internals/cdecl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file cdecl.h 11 | * \brief C-related declarations 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef CDECL_H 20 | #define CDECL_H 21 | 22 | #ifdef __cplusplus 23 | # define SPX_BEGIN_C_DECLS__ extern "C" { 24 | # define SPX_END_C_DECLS__ } 25 | #else 26 | # define SPX_BEGIN_C_DECLS__ /* nothing */ 27 | # define SPX_END_C_DECLS__ /* nothing */ 28 | #endif // __cplusplus 29 | 30 | #endif // CDECL_H 31 | 32 | // vim:expandtab:tabstop=8:shiftwidth=4:softtabstop=4 33 | -------------------------------------------------------------------------------- /include/sparsex/internals/futex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2016, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2016, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file futex.h 11 | * \brief Linux futex wrapper 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2016 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_FUTEX_H 20 | #define SPARSEX_INTERNALS_FUTEX_H 21 | 22 | #include 23 | 24 | SPX_BEGIN_C_DECLS__ 25 | 26 | void futex_wait(int *addr, int val); 27 | void futex_wake(int *addr, int count); 28 | 29 | SPX_END_C_DECLS__ 30 | 31 | #endif // SPARSEX_INTERNALS_FUTEX_H 32 | -------------------------------------------------------------------------------- /include/sparsex/internals/logger/LoggerUtil.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file LoggerUtil.hpp 11 | * \brief Logging utilities 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_LOGGER_LOGGER_UTIL_HPP 20 | #define SPARSEX_INTERNALS_LOGGER_LOGGER_UTIL_HPP 21 | 22 | #include 23 | 24 | SPX_BEGIN_C_DECLS__ 25 | 26 | void DisableLogging(); 27 | void EnableAllConsole(); 28 | void EnableAllFile(const char *log_file); 29 | void UseFile(const char *log_file); 30 | void EnableErrorConsole(); 31 | void EnableErrorFile(); 32 | void EnableWarningConsole(); 33 | void EnableWarningFile(); 34 | void EnableInfoConsole(); 35 | void EnableInfoFile(); 36 | void EnableVerboseConsole(); 37 | void EnableVerboseFile(); 38 | void EnableDebugConsole(); 39 | void EnableDebugFile(); 40 | 41 | void log_error(const char *msg); 42 | void log_warning(const char *msg); 43 | void log_verbose(const char *msg); 44 | 45 | SPX_END_C_DECLS__ 46 | 47 | #endif // SPARSEX_INTERNALS_LOGGER_LOGGER_UTIL_HPP 48 | 49 | -------------------------------------------------------------------------------- /include/sparsex/internals/logger/OutputPolicy.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file OutputPolicy.hpp 11 | * \brief Output policies for logging 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_INTERNALS_LOGGER_OUTPUT_POLICY_HPP 20 | #define SPARSEX_INTERNALS_LOGGER_OUTPUT_POLICY_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | namespace sparsex { 31 | namespace logging { 32 | 33 | template 34 | class Singleton 35 | { 36 | public: 37 | // In C++11 this is thread safe 38 | static T& GetInstance() 39 | { 40 | static T obj; 41 | return obj; 42 | } 43 | }; 44 | 45 | class NullPolicy : public Singleton 46 | { 47 | public: 48 | typedef ostringstream buffer_type; 49 | void operator()(const buffer_type &buffer) {} 50 | }; 51 | 52 | /* Logging policy that directs all the output of the logger to stdout */ 53 | class StdPolicy : public Singleton 54 | { 55 | public: 56 | typedef ostringstream buffer_type; 57 | void operator()(const buffer_type &buffer); 58 | 59 | private: 60 | pthread_mutex_t write_mutex_; 61 | }; 62 | 63 | /* Logging policy that directs all the output of the logger to a file */ 64 | class FilePolicy : public Singleton 65 | { 66 | public: 67 | typedef ostringstream buffer_type; 68 | void operator()(const buffer_type &buffer); 69 | void Init(const char *log_file); 70 | ~FilePolicy() 71 | { 72 | os_.close(); 73 | } 74 | 75 | private: 76 | ofstream os_; 77 | pthread_mutex_t write_mutex_; 78 | }; 79 | 80 | typedef boost::function OutputHandler; 81 | 82 | } // end of namespace logging 83 | } // end of namespace sparsex 84 | 85 | #endif // SPARSEX_INTERNALS_LOGGER_OUTPUT_POLICY_HPP 86 | -------------------------------------------------------------------------------- /include/sparsex/internals/numa_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2012, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2011-2012, Vasileios Karakasis 4 | * Copyright (C) 2011-2012, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file numa_util.h 12 | * \brief NUMA utilitiy functions 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_INTERNALS_NUMA_UTIL_H 21 | #define SPARSEX_INTERNALS_NUMA_UTIL_H 22 | 23 | #include 24 | #include 25 | 26 | SPX_BEGIN_C_DECLS__ 27 | /* 28 | * Custom interleaved allocation. 29 | * 30 | * @size size in bytes of the full allocation (will be rounded to page size) 31 | * @parts sizes in bytes of individual partitions (will be rounded to 32 | * page size) 33 | * @nr_parts number of partitions 34 | * @nodes memory nodes to bind each partition 35 | * 36 | * @return pointer to the newly allocated area. Free with free_interleaved(). 37 | */ 38 | void *alloc_interleaved(size_t size, size_t *parts, size_t nr_parts, 39 | int *nodes); 40 | void *alloc_onnode(size_t size, int node); 41 | void free_interleaved(void *addr, size_t length); 42 | int check_interleaved(void *addr, const size_t *parts, 43 | size_t nr_parts, const int *nodes); 44 | int check_region(void *addr, size_t size, int node); 45 | void print_alloc_status(const char *data_descr, int err); 46 | 47 | SPX_END_C_DECLS__ 48 | 49 | #endif /* SPARSEX_INTERNALS_NUMA_UTIL_H */ 50 | -------------------------------------------------------------------------------- /include/sparsex/sparsex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * Copyright (C) 2013, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file sparsex.h 12 | * \brief SparseX header files. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | * 19 | * \mainpage 20 | * The SparseX library is a collection of low-level primitives written in the 21 | * C/C++ programming languages, that provides the means to developers of solver 22 | * libraries and of scientific and engineering applications to easily attain 23 | * high performance of the Sparse Matrix-by-Vector multiplication kernel (SpMV) 24 | * on modern multicore architectures. 25 | */ 26 | 27 | #ifndef SPARSEX_SPARSEX_H 28 | #define SPARSEX_SPARSEX_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #endif /* SPARSEX_SPARSEX_H */ 37 | -------------------------------------------------------------------------------- /include/sparsex/timing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * Copyright (C) 2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file timing.h 12 | * \brief Timing routines. 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_TIMING_H 20 | #define SPARSEX_TIMING_H 21 | 22 | #include 23 | 24 | struct timer { 25 | struct timeval elapsed_time; 26 | struct timeval timestamp; 27 | }; 28 | typedef struct timer spx_timer_t; 29 | 30 | /** 31 | * Initializes a timer object. 32 | * 33 | * @param[in] t timer object to be initialized. 34 | */ 35 | static inline void spx_timer_clear(spx_timer_t *t) 36 | { 37 | timerclear(&(t->elapsed_time)); 38 | timerclear(&(t->timestamp)); 39 | } 40 | 41 | /** 42 | * Starts a timer object. 43 | * 44 | * @param[in] t timer object to be launched. 45 | */ 46 | static inline void spx_timer_start(spx_timer_t *t) 47 | { 48 | if (gettimeofday(&(t->timestamp), NULL) < 0) { 49 | /* cerr << "timer error: gettimeofday()" << endl; */ 50 | exit(1); 51 | } 52 | } 53 | 54 | /** 55 | * Pauses a timer object. 56 | * 57 | * @param[in] t timer object to be paused. 58 | */ 59 | static inline void spx_timer_pause(spx_timer_t *t) 60 | { 61 | struct timeval t_stop; 62 | struct timeval t_interval; 63 | 64 | if (gettimeofday(&t_stop, NULL) < 0) { 65 | /* cerr << "timer error: gettimeofday()" << endl; */ 66 | exit(1); 67 | } 68 | 69 | timersub(&t_stop, &(t->timestamp), &t_interval); 70 | timeradd(&(t->elapsed_time), &t_interval, &(t->elapsed_time)); 71 | } 72 | 73 | /** 74 | * Returns the elapsed time in seconds. 75 | * 76 | * @param[in] t a timer object. 77 | * @return elapsed seconds. 78 | */ 79 | static inline double spx_timer_get_secs(spx_timer_t *t) 80 | { 81 | return t->elapsed_time.tv_sec + 82 | t->elapsed_time.tv_usec / (double) 1000000; 83 | } 84 | 85 | #endif /* SPARSEX_TIMING_H */ 86 | -------------------------------------------------------------------------------- /include/sparsex/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013, Athena Elafrou 4 | * Copyright (C) 2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file types.h 12 | * \brief Available indexing and value types. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef SPARSEX_TYPES_H 21 | #define SPARSEX_TYPES_H 22 | 23 | #include 24 | 25 | #ifdef SPX_INDEX_TYPE 26 | typedef SPX_INDEX_TYPE spx_index_t; 27 | #else 28 | typedef int spx_index_t; 29 | #endif 30 | 31 | #ifdef SPX_VALUE_TYPE 32 | typedef SPX_VALUE_TYPE spx_value_t; 33 | #else 34 | typedef double spx_value_t; 35 | #endif 36 | 37 | #endif /* SPARSEX_TYPES_H */ 38 | -------------------------------------------------------------------------------- /include/sparsex/version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file version.h 11 | * \brief Makes available the version of the SparseX library programmatically. 12 | * 13 | * This file is guaranteed to change with every release of the package. 14 | * 15 | * \author Computing Systems Laboratory (CSLab), NTUA 16 | * \date 2011–2014 17 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 18 | * for details. 19 | */ 20 | 21 | #ifndef SPARSEX_VERSION_H 22 | #define SPARSEX_VERSION_H 23 | 24 | /** 25 | * The version number of this package. 26 | * 27 | * The version number of the SparseX library is computed as follows: 28 | * 29 | * SPARSEX_VERSION = 30 | * 100000*MAJOR_VERSION + 1000*MINOR_VERSION + PATCH_LEVEL 31 | * 32 | * Inversely, the major/minor versions and the patch level of the package can be 33 | * computed as follows: 34 | * 35 | * MAJOR_VERSION = SPARSEX_VERSION / 100000
36 | * MINOR_VERSION = SPARSEX_VERSION / 1000 % 100
37 | * PATCH_LEVEL = SPARSEX_VERSION % 1000
38 | */ 39 | #define SPARSEX_VERSION @AX_PACKAGE_VERSION_NUMBER@ 40 | #define SPARSEX_LIB_VERSION "@PACKAGE_VERSION@" 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /m4check/ax_check_icu.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_check_icu.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_ICU(version, action-if, action-if-not) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Defines ICU_LIBS, ICU_CFLAGS, ICU_CXXFLAGS. See icu-config(1) man page. 12 | # 13 | # LICENSE 14 | # 15 | # Copyright (c) 2008 Akos Maroy 16 | # Copyright (c) 2009 Vasileios Karakasis 17 | # 18 | # Copying and distribution of this file, with or without modification, are 19 | # permitted in any medium without royalty provided the copyright notice 20 | # and this notice are preserved. This file is offered as-is, without any 21 | # warranty. 22 | # 23 | # MODIFICATIONS 24 | # 25 | # 2009-12-07 bkk Corrected how ICU_LIBS is set. 26 | # 2009-11-07 bkk Changes in how flags are set. Also ICU_LDFLAGS now 27 | # supported. 28 | 29 | #serial 6 30 | AC_DEFUN([AX_CHECK_ICU], [ 31 | succeeded=no 32 | 33 | if test -z "$ICU_CONFIG"; then 34 | AC_PATH_PROG(ICU_CONFIG, icu-config, no) 35 | fi 36 | 37 | if test "$ICU_CONFIG" = "no" ; then 38 | echo "*** The icu-config script could not be found. Make sure it is" 39 | echo "*** in your path, and that taglib is properly installed." 40 | echo "*** Or see http://ibm.com/software/globalization/icu/" 41 | else 42 | ICU_VERSION=`$ICU_CONFIG --version` 43 | AC_MSG_CHECKING(for ICU >= $1) 44 | VERSION_CHECK=`expr $ICU_VERSION \>\= $1` 45 | if test "$VERSION_CHECK" = "1" ; then 46 | AC_MSG_RESULT(yes) 47 | succeeded=yes 48 | 49 | AC_MSG_CHECKING(ICU_CPPFLAGS) 50 | ICU_CPPFLAGS=`$ICU_CONFIG --cppflags-searchpath` 51 | AC_MSG_RESULT($ICU_CPPFLAGS) 52 | 53 | AC_MSG_CHECKING(ICU_CFLAGS) 54 | ICU_CFLAGS=`$ICU_CONFIG --cflags` 55 | AC_MSG_RESULT($ICU_CFLAGS) 56 | 57 | AC_MSG_CHECKING(ICU_CXXFLAGS) 58 | ICU_CXXFLAGS=`$ICU_CONFIG --cxxflags` 59 | AC_MSG_RESULT($ICU_CXXFLAGS) 60 | 61 | AC_MSG_CHECKING(ICU_LDFLAGS) 62 | ICU_LDFLAGS=`$ICU_CONFIG --ldflags-searchpath` 63 | AC_MSG_RESULT($ICU_LDFLAGS) 64 | 65 | AC_MSG_CHECKING(ICU_LIBS) 66 | ICU_LIBS=`$ICU_CONFIG --ldflags` 67 | ICU_LIBS="$ICU_LIBS `$ICU_CONFIG --ldflags-icuio`" 68 | AC_MSG_RESULT($ICU_LIBS) 69 | else 70 | ICU_CPPFLAGS="" 71 | ICU_CFLAGS="" 72 | ICU_CXXFLAGS="" 73 | ICU_LDFLAGS="" 74 | ICU_LIBS="" 75 | ## If we have a custom action on failure, don't print errors, but 76 | ## do set a variable so people can do so. 77 | ifelse([$3], ,echo "can't find ICU >= $1",) 78 | fi 79 | 80 | AC_SUBST(ICU_CPPFLAGS) 81 | AC_SUBST(ICU_CFLAGS) 82 | AC_SUBST(ICU_CXXFLAGS) 83 | AC_SUBST(ICU_LDFLAGS) 84 | AC_SUBST(ICU_LIBS) 85 | fi 86 | 87 | if test $succeeded = yes; then 88 | ifelse([$2], , :, [$2]) 89 | else 90 | ifelse([$3], , AC_MSG_ERROR([Library requirements (ICU) not met.]), [$3]) 91 | fi 92 | ]) 93 | -------------------------------------------------------------------------------- /m4check/ax_check_prog.m4: -------------------------------------------------------------------------------- 1 | dnl 2 | dnl ax_check_prog.m4 -- Check for a specific program 3 | dnl 4 | dnl Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | dnl Copyright (C) 2014, Vasileios Karakasis 6 | dnl All rights reserved. 7 | dnl 8 | dnl This file is distributed under the BSD License. See LICENSE.txt for details. 9 | dnl 10 | 11 | dnl 12 | dnl AX_CHECK_PROG(prog, [variable], [path = $PATH]) 13 | dnl 14 | dnl Check for `prog' in `path' and set `variable' to the absolute filename 15 | dnl of the program, if found. Path directories must not contain spaces. 16 | dnl 17 | dnl AC_SUBST([variable]) 18 | dnl 19 | AC_DEFUN([AX_CHECK_PROG], 20 | [ 21 | AC_REQUIRE([AC_PROG_SED]) 22 | m4_if([$#], [0], 23 | [m4_errprintn([Too few arguments to $0.]) m4_exit(1)]) 24 | 25 | user_prog=$1 26 | user_path=$3 27 | 28 | AC_MSG_CHECKING([$user_prog]) 29 | if test -z $user_path; then 30 | user_path=$PATH 31 | fi 32 | 33 | search_dirs=`echo $user_path | $SED -e 's/:/ /g'` 34 | for d in $search_dirs; do 35 | if test -e "$d/$user_prog" && test -x "$d/$user_prog"; then 36 | prog_found="$d/$user_prog" 37 | break 38 | fi 39 | done 40 | 41 | if test -z $prog_found; then 42 | AC_MSG_RESULT([no]) 43 | else 44 | m4_ifblank($2, UPPERCASE($1), $2)=$prog_found 45 | AC_SUBST(m4_ifblank($2, UPPERCASE($1), $2)) 46 | AC_MSG_RESULT([yes]) 47 | fi 48 | ]) 49 | -------------------------------------------------------------------------------- /m4check/ax_platforms.m4: -------------------------------------------------------------------------------- 1 | dnl 2 | dnl platforms.m4 -- Macros related to system platforms. 3 | dnl 4 | dnl Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | dnl Copyright (C) 2014, Vasileios Karakasis 6 | dnl All rights reserved. 7 | dnl 8 | dnl This file is distributed under the BSD License. See LICENSE.txt for details. 9 | dnl 10 | 11 | dnl 12 | dnl AX_PLATFORM 13 | dnl 14 | dnl Returns in `ax_platform' a simple string describing the underlying 15 | dnl platform. The returned value may be one of `linux' or `darwin'. If the 16 | dnl underlying platform is not any of these, it returns the value of the 17 | dnl `build_os' variable. 18 | dnl 19 | 20 | AC_DEFUN([AX_PLATFORM], 21 | [ 22 | AC_REQUIRE([AC_CANONICAL_BUILD]) 23 | AC_REQUIRE([AC_CANONICAL_HOST]) 24 | 25 | case $build_os in 26 | linux*) 27 | ax_platform="linux" ;; 28 | darwin*) 29 | ax_platform="darwin" ;; 30 | *) 31 | ax_platform=$build_os ;; 32 | esac 33 | ]) 34 | 35 | dnl 36 | dnl AX_SYSTEM_MEMORY_NODES 37 | dnl 38 | dnl Returns the number of memory nodes in the system. 39 | dnl This macro works for standard GNU/Linux systems with kernel >= 2.6. 40 | dnl In this case the number of memory nodes in the system is returned in 41 | dnl the `ax_memory_nodes' variable. If the number of memory nodes cannot 42 | dnl be determined, zero is returned. 43 | dnl 44 | dnl 45 | AC_DEFUN([AX_SYSTEM_MEMORY_NODES], 46 | [ 47 | ax_memory_nodes=`/bin/ls -d /sys/devices/system/node/node* 2> /dev/null | /usr/bin/wc -l` 48 | ]) -------------------------------------------------------------------------------- /m4check/ax_prog_doxygen.m4: -------------------------------------------------------------------------------- 1 | dnl 2 | dnl ax_prog_doxygen.m4 -- Check for and set up doxygen 3 | dnl 4 | dnl Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | dnl Copyright (C) 2014, Vasileios Karakasis 6 | dnl All rights reserved. 7 | dnl 8 | dnl This file is distributed under the BSD License. See LICENSE.txt for details. 9 | dnl 10 | 11 | AC_DEFUN([AX_PROG_DOXYGEN], 12 | [ 13 | AX_CHECK_PROG([doxygen]) 14 | if test -z $DOXYGEN; then 15 | AC_MSG_WARN([Could not find `doxygen' in your path. dnl 16 | You may not be able to generate the documentation of the package.]) 17 | else 18 | dx_docdir=doc 19 | dx_api_subdir=api 20 | dx_devel_subdir=devel 21 | 22 | DX_CONF_API=Doxyfile.api 23 | DX_CONF_DEVEL=Doxyfile.devel 24 | DX_CONF_TAGFILE=$PACKAGE_TARNAME.tag 25 | DX_CONF_HTML_DIR=html 26 | 27 | AC_SUBST(dx_docdir) 28 | AC_SUBST(dx_api_subdir) 29 | AC_SUBST(dx_devel_subdir) 30 | AC_SUBST(DX_CONF_API) 31 | AC_SUBST(DX_CONF_DEVEL) 32 | AC_SUBST(DX_CONF_HTML_DIR) 33 | AC_SUBST(DX_CONF_TAGFILE) 34 | fi 35 | 36 | AM_CONDITIONAL([SPX_GENERATE_DOC], [ test ! -z $DOXYGEN ]) 37 | ]) 38 | 39 | -------------------------------------------------------------------------------- /m4check/verbose_rules.am: -------------------------------------------------------------------------------- 1 | # 2 | # resources_rules.am 3 | # 4 | # Adds rules and definitions for automatic resource bundles generation. 5 | # 6 | # Copyright (C) 2010, KRK. 7 | # All righrs reserved. 8 | # 9 | # Modification history: 10 | # 11 | # Date Name Description 12 | # 2010-02-15 bkk Creation. 13 | # 14 | 15 | # Handle verbosity 16 | verbose = $(verbose_$(V)) 17 | verbose_ = $(verbose_$(AM_DEFAULT_VERBOSITY)) 18 | 19 | verbosity_opt = $(verbosity_opt_$(V)) 20 | verbosity_opt_ = $(verbosity_opt_$(AM_DEFAULT_VERBOSITY)) 21 | -------------------------------------------------------------------------------- /scripts/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am 3 | # 4 | # Build installable scripts. 5 | # 6 | # Copyright (C) 2009-2013, KRK. 7 | # All righrs reserved. 8 | # 9 | # Modification history: 10 | # 11 | # Date Name Description 12 | # 2013-12-24 -- Automatically generated by confgen.sh 1.1_unstable. 13 | # 14 | 15 | AM_DEFAULT_VERBOSITY = 0 16 | 17 | bin_SCRIPTS = sparsex-config 18 | CLEANFILES = $(bin_SCRIPTS) 19 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All rights reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | SUBDIRS = internals templates api examples 13 | 14 | if SPX_BUILD_BENCH 15 | SUBDIRS += bench 16 | endif 17 | -------------------------------------------------------------------------------- /src/api/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- SparseX C api 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All rights reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | ACLOCAL_AMFLAGS = -I m4check 13 | 14 | AM_CPPFLAGS = \ 15 | -I$(top_builddir)/include \ 16 | -I$(top_srcdir)/include \ 17 | $(AX_CPPFLAGS) 18 | 19 | AM_CFLAGS = $(AX_CFLAGS) 20 | AM_CXXFLAGS = $(AX_CXXFLAGS) 21 | AM_LDFLAGS = \ 22 | -L$(top_builddir)/src/internals/.libs \ 23 | $(AX_LDFLAGS) 24 | 25 | lib_LTLIBRARIES = libsparsex.la 26 | # Dummy C++ source to cause C++ linking 27 | nodist_EXTRA_libsparsex_la_SOURCES = dummy.cxx 28 | libsparsex_la_SOURCES = \ 29 | common.c \ 30 | error.c \ 31 | matvec.c 32 | 33 | libsparsex_la_LDFLAGS = -version-info 1:2:0 34 | libsparsex_la_LIBADD = \ 35 | $(top_builddir)/src/internals/.libs/libsparseximpl.la 36 | -------------------------------------------------------------------------------- /src/api/common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * Copyright (C) 2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file common.c 12 | * \brief Common library utilities and definitions. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | 22 | void spx_log_disable_all() 23 | { 24 | DisableLogging(); 25 | } 26 | 27 | void spx_log_error_console() 28 | { 29 | EnableErrorConsole(); 30 | } 31 | 32 | void spx_log_warning_console() 33 | { 34 | EnableWarningConsole(); 35 | } 36 | 37 | void spx_log_info_console() 38 | { 39 | EnableInfoConsole(); 40 | } 41 | 42 | void spx_log_verbose_console() 43 | { 44 | EnableVerboseConsole(); 45 | } 46 | 47 | void spx_log_debug_console() 48 | { 49 | EnableDebugConsole(); 50 | } 51 | 52 | void spx_log_error_file() 53 | { 54 | EnableErrorFile(); 55 | } 56 | 57 | void spx_log_warning_file() 58 | { 59 | EnableWarningFile(); 60 | } 61 | 62 | void spx_log_info_file() 63 | { 64 | EnableInfoFile(); 65 | } 66 | 67 | void spx_log_debug_file() 68 | { 69 | EnableDebugFile(); 70 | } 71 | 72 | void spx_log_all_console() 73 | { 74 | EnableAllConsole(); 75 | } 76 | 77 | void spx_log_all_file(const char *file) 78 | { 79 | EnableAllFile(file); 80 | } 81 | 82 | void spx_log_set_file(const char *file) 83 | { 84 | UseFile(file); 85 | } 86 | 87 | void spx_init() 88 | { 89 | EnableWarningConsole(); 90 | } 91 | 92 | void spx_finalize() 93 | { 94 | /* Cleanups */ 95 | } 96 | 97 | void *malloc_internal(size_t x, const char *sourcefile, unsigned long lineno, 98 | const char *function) 99 | { 100 | void *ret; 101 | ret = malloc(x); 102 | if (!ret) { 103 | err_handle(SPX_ERR_MEM_ALLOC, sourcefile, lineno, function, NULL); 104 | exit(1); 105 | } 106 | 107 | return ret; 108 | } 109 | 110 | void free_internal(void *ptr, const char *sourcefile, unsigned long lineno, 111 | const char *function) 112 | { 113 | if (!ptr) { 114 | err_handle(SPX_ERR_MEM_FREE, sourcefile, lineno, function, NULL); 115 | exit(1); 116 | } 117 | 118 | free(ptr); 119 | ptr = NULL; 120 | } 121 | -------------------------------------------------------------------------------- /src/bench/Bench.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Bench.hpp 11 | * \brief Benchmarking interface 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef BENCH_HPP 20 | #define BENCH_HPP 21 | 22 | #include "BenchUtil.hpp" 23 | 24 | using namespace bench; 25 | 26 | /* 27 | * Browse all the matrices available in the specified directory and solve the 28 | * SpMV kernel with the specified #library or with all available libraries 29 | * (SparseX, Intel MKL, pOSKI) if #library is not specified. The results of 30 | * each solve are printed in the standard output and optionally in the provided 31 | * #stats_file. 32 | * 33 | * @param[in] directory the directory of the MMF files. 34 | * @param[in] library the library to be used for computing the SpMV 35 | * kernel. 36 | * @param[in] stats_file an optional file for outputting benchmark results. 37 | * @param[in] loops the numbers of SpMV iterations. 38 | * @param[in] outer_loops the number of repeats of the benchmark. 39 | */ 40 | void Bench_Directory(const char *directory, const char *library, 41 | const char *stats_file); 42 | 43 | /* 44 | * Solve the SpMV kernel with the specified #library or with all available 45 | * libraries (SparseX, Intel MKL, pOSKI) if #library is not specified for the 46 | * given matrix in the MMF format. The results of each solve are printed in 47 | * the standard output and optionally in the provided #stats_file. 48 | * 49 | * @param[in] mmf_file the MMF file where the matrix is stored. 50 | * @param[in] library the library to be used for computing the SpMV kernel. 51 | * @param[in] stats_file an optional file for outputting benchmark results. 52 | * @param[in] loops the numbers of SpMV iterations. 53 | * @param[in] outer_loops the number of repeats of the benchmark. 54 | */ 55 | void Bench_Matrix(const char *mmf_file, const char *library, 56 | const char *stats_file); 57 | 58 | void Bench_Matrix(const char *mmf_file, SpmvFn fn, const char *stats_file); 59 | 60 | #endif // BENCH_HPP 61 | -------------------------------------------------------------------------------- /src/bench/BenchUtil.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file BenchUtil.hpp 11 | * \brief Benchmarking utilities 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef BENCH_UTIL_HPP 20 | #define BENCH_UTIL_HPP 21 | 22 | #ifdef HAVE_CONFIG_H 23 | # include "build_config.h" 24 | #endif 25 | 26 | #if SPX_BENCH_POSKI 27 | # include "PoskiModule.hpp" 28 | #endif 29 | #if SPX_BENCH_MKL 30 | # include "MklModule.hpp" 31 | #endif 32 | #include "SparsexModule.hpp" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | using namespace std; 40 | 41 | namespace bench { 42 | 43 | /* The available libraries */ 44 | enum library { 45 | SparseX, 46 | MKL, 47 | pOSKI 48 | }; 49 | 50 | typedef boost::function SpmvFn; 54 | 55 | class DirectoryIterator 56 | { 57 | public: 58 | DirectoryIterator(const char *directory) 59 | : directory_(directory), 60 | directory_id_(0), 61 | file_(), 62 | is_valid_(0) 63 | { 64 | directory_id_ = opendir(directory); 65 | if (!directory_id_) { 66 | cerr << "[BENCH]: failed to open directory." << endl; 67 | exit(1); 68 | } else { 69 | is_valid_ = true; 70 | } 71 | ++(*this); 72 | } 73 | 74 | ~DirectoryIterator() 75 | { 76 | if (directory_id_) 77 | closedir(directory_id_); 78 | } 79 | 80 | void operator++() 81 | { 82 | struct dirent *cur_entry = 0; 83 | while (((cur_entry = readdir(directory_id_)) != 0) 84 | && dot_or_dot_dot(cur_entry->d_name)); 85 | if (cur_entry != 0) { 86 | if (cur_entry->d_type != DT_DIR) { 87 | string matrix_name_ = static_cast(cur_entry->d_name); 88 | file_ = directory_ + "/" + matrix_name_; 89 | is_valid_ = true; 90 | } else { 91 | is_valid_ = false; 92 | } 93 | } else { 94 | is_valid_ = false; 95 | } 96 | } 97 | 98 | operator bool() const 99 | { 100 | return is_valid_; 101 | } 102 | 103 | string &filename() 104 | { 105 | return file_; 106 | } 107 | 108 | private: 109 | const string directory_; 110 | DIR *directory_id_; 111 | string file_; 112 | bool is_valid_; 113 | 114 | DirectoryIterator() {} 115 | 116 | inline bool dot_or_dot_dot(const char *name) 117 | { 118 | return name[0] == '.' 119 | && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')); 120 | } 121 | }; 122 | 123 | } // end of namespace bench 124 | 125 | #endif // BENCH_UTIL_HPP 126 | -------------------------------------------------------------------------------- /src/bench/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- Makefile for library benchmarks 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All rights reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | ACLOCAL_AMFLAGS = -I m4check 13 | 14 | AM_CPPFLAGS = \ 15 | -I$(top_builddir)/include \ 16 | -I$(top_srcdir)/include \ 17 | -I$(top_srcdir)/src/bench \ 18 | $(AX_CPPFLAGS) 19 | AM_CXXFLAGS = $(AX_CXXFLAGS) 20 | AM_LDFLAGS = \ 21 | -L$(top_builddir)/src/api/.libs \ 22 | $(AX_LDFLAGS) 23 | 24 | noinst_HEADERS = \ 25 | Bench.hpp \ 26 | BenchUtil.hpp \ 27 | MklModule.hpp \ 28 | Mmf.hpp \ 29 | PoskiModule.hpp \ 30 | SparsexModule.hpp \ 31 | Timer.hpp 32 | 33 | noinst_PROGRAMS = bench_spmv 34 | bench_spmv_SOURCES = \ 35 | Bench.cpp \ 36 | main.cpp \ 37 | Timer.cpp \ 38 | SparsexModule.cpp 39 | 40 | if SPX_BUILD_BENCH_MKL 41 | AM_CPPFLAGS += $(MKL_CPPFLAGS) 42 | AM_CXXFLAGS += $(MKL_CXXFLAGS) 43 | AM_LDFLAGS += $(MKL_LDFLAGS) 44 | bench_spmv_SOURCES += MklModule.cpp 45 | endif 46 | 47 | if SPX_BUILD_BENCH_POSKI 48 | AM_CPPFLAGS += $(POSKI_CPPFLAGS) 49 | AM_CXXFLAGS += $(POSKI_CXXFLAGS) 50 | AM_LDFLAGS += $(POSKI_LDFLAGS) 51 | bench_spmv_SOURCES += PoskiModule.cpp 52 | endif 53 | 54 | bench_spmv_LDFLAGS = -rpath $(LLVM_LIBDIR) 55 | bench_spmv_LDADD = \ 56 | $(top_builddir)/src/api/.libs/libsparsex.la 57 | 58 | if SPX_BUILD_BENCH_MKL 59 | bench_spmv_LDADD += $(MKL_LIBS) 60 | endif 61 | 62 | if SPX_BUILD_BENCH_POSKI 63 | bench_spmv_LDADD += $(POSKI_LIBS) 64 | endif 65 | -------------------------------------------------------------------------------- /src/bench/MklModule.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file MklModule.cpp 11 | * \brief The SpMV kernel implemented with Intel MKL 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include "MklModule.hpp" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace std; 28 | 29 | extern string MATRIX; 30 | extern unsigned int OUTER_LOOPS; 31 | extern unsigned long LOOPS; 32 | extern Timer t; 33 | 34 | /* SpMV kernel implemented with Intel MKL */ 35 | void mkl_spmv(spx_index_t *rowptr, spx_index_t *colind, spx_value_t *values, 36 | spx_index_t nrows, spx_index_t ncols, spx_index_t nnz, 37 | spx_value_t *x, spx_value_t *y, 38 | spx_value_t ALPHA, spx_value_t BETA) 39 | { 40 | /* 1. Matrix loading phase */ 41 | MKL_INT *pointerB, *pointerE; 42 | char transa; 43 | char matdescra[6]; 44 | 45 | transa = 'n'; 46 | matdescra[0] = 'g'; 47 | matdescra[1] = '-'; 48 | matdescra[2] = '-'; 49 | matdescra[3] = 'c'; 50 | 51 | pointerB = (MKL_INT *) malloc(sizeof(MKL_INT) * nrows); 52 | pointerE = (MKL_INT *) malloc(sizeof(MKL_INT) * nrows); 53 | for (int i = 0; i < nrows; i++) { 54 | pointerB[i] = rowptr[i]; 55 | pointerE[i] = rowptr[i+1]; 56 | } 57 | 58 | /* 2. SpMV benchmarking phase */ 59 | vector mt(OUTER_LOOPS); 60 | for (size_t i = 0; i < OUTER_LOOPS; i++) { 61 | t.Clear(); 62 | t.Start(); 63 | for (size_t j = 0; j < LOOPS; j++) { 64 | mkl_dcsrmv(&transa, &nrows, &ncols, &ALPHA, matdescra, values, 65 | colind, pointerB, pointerE, x, &BETA, y); 66 | } 67 | t.Pause(); 68 | mt[i] = t.ElapsedTime(); 69 | } 70 | 71 | sort(mt.begin(), mt.end()); 72 | double mt_median = 73 | (OUTER_LOOPS % 2) ? mt[((OUTER_LOOPS+1)/2)-1] 74 | : ((mt[OUTER_LOOPS/2-1] + mt[OUTER_LOOPS/2])/2); 75 | double flops = (double)(LOOPS*nnz*2)/((double)1000*1000*mt_median); 76 | cout << "m: " << MATRIX 77 | << " mt(median): " << mt_median 78 | << " flops: " << flops << endl; 79 | 80 | /* 3. Cleanup */ 81 | free(pointerB); 82 | free(pointerE); 83 | } 84 | -------------------------------------------------------------------------------- /src/bench/MklModule.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file MklModule.hpp 11 | * \brief The SpMV kernel implemented with Intel MKL 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef MKL_MODULE_HPP 20 | #define MKL_MODULE_HPP 21 | 22 | #ifdef HAVE_CONFIG_H 23 | # include "build_config.h" 24 | #endif 25 | 26 | #include "Timer.hpp" 27 | #include 28 | #include 29 | #include 30 | 31 | void mkl_spmv(spx_index_t *rowptr, spx_index_t *colind, spx_value_t *values, 32 | spx_index_t nrows, spx_index_t ncols, spx_index_t nnz, 33 | spx_value_t *x, spx_value_t *y, 34 | spx_value_t ALPHA, spx_value_t BETA); 35 | 36 | #endif // MKL_MODULE_HPP 37 | 38 | -------------------------------------------------------------------------------- /src/bench/PoskiModule.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file PoskiModule.cpp 11 | * \brief The SpMV kernel implemented with pOSKI 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include "PoskiModule.hpp" 20 | #include 21 | #include 22 | 23 | using namespace std; 24 | 25 | extern string MATRIX; 26 | extern unsigned int OUTER_LOOPS; 27 | extern unsigned long LOOPS; 28 | extern unsigned int NR_THREADS; 29 | extern Timer t; 30 | 31 | /* SpMV kernel implemented with pOSKI */ 32 | void poski_spmv(spx_index_t *Aptr, spx_index_t *Aind, spx_value_t *Aval, 33 | spx_index_t nrows, spx_index_t ncols, spx_index_t nnz, 34 | spx_value_t *x, spx_value_t *y, 35 | spx_value_t ALPHA, spx_value_t BETA) 36 | { 37 | poski_Init(); 38 | 39 | /* 1. Matrix loading phase */ 40 | poski_threadarg_t *poski_thread = poski_InitThreads(); 41 | poski_ThreadHints(poski_thread, NULL, POSKI_THREADPOOL, NR_THREADS); 42 | // poski_ThreadHints(poski_thread, NULL, POSKI_PTHREAD, NR_THREADS); 43 | poski_partitionarg_t *partitionMat = poski_partitionMatHints(OneD, NR_THREADS, 44 | KERNEL_MatMult, 45 | OP_NORMAL); 46 | poski_mat_t A_tunable = 47 | poski_CreateMatCSR(Aptr, Aind, Aval, nrows, ncols, nnz, SHARE_INPUTMAT, 48 | poski_thread, partitionMat, 2, INDEX_ZERO_BASED, 49 | MAT_GENERAL); 50 | 51 | /* 2. Vector loading */ 52 | poski_partitionvec_t *partitionVecX = 53 | poski_PartitionVecHints(A_tunable, KERNEL_MatMult, OP_NORMAL, INPUTVEC); 54 | poski_vec_t x_view = poski_CreateVec(x, ncols, STRIDE_UNIT, partitionVecX); 55 | poski_partitionvec_t *partitionVecY = 56 | poski_PartitionVecHints(A_tunable, KERNEL_MatMult, OP_NORMAL, OUTPUTVEC); 57 | poski_vec_t y_view = poski_CreateVec(y, nrows, STRIDE_UNIT, partitionVecY); 58 | 59 | /* 3. Tuning phase */ 60 | t.Clear(); 61 | t.Start(); 62 | poski_TuneHint_MatMult(A_tunable, OP_NORMAL, ALPHA, x_view, BETA, 63 | y_view, ALWAYS_TUNE_AGGRESSIVELY); 64 | poski_TuneMat(A_tunable); 65 | t.Pause(); 66 | double pt = t.ElapsedTime(); 67 | 68 | /* 4. SpMV benchmarking phase */ 69 | vector mt(OUTER_LOOPS); 70 | for (size_t i = 0; i < OUTER_LOOPS; i++) { 71 | t.Clear(); 72 | t.Start(); 73 | for (size_t j = 0; j < LOOPS; j++) { 74 | poski_MatMult(A_tunable, OP_NORMAL, ALPHA, x_view, BETA, y_view); 75 | } 76 | t.Pause(); 77 | mt[i] = t.ElapsedTime(); 78 | } 79 | 80 | sort(mt.begin(), mt.end()); 81 | double mt_median = 82 | (OUTER_LOOPS % 2) ? mt[((OUTER_LOOPS+1)/2)-1] 83 | : ((mt[OUTER_LOOPS/2-1] + mt[OUTER_LOOPS/2])/2); 84 | double flops = (double)(LOOPS*nnz*2)/((double)1000*1000*mt_median); 85 | cout << "m: " << MATRIX 86 | << " pt: " << pt 87 | << " mt(median): " << mt_median 88 | << " flops: " << flops << endl; 89 | 90 | /* 4. Cleanup */ 91 | poski_DestroyPartitionVec(partitionVecX); 92 | poski_DestroyPartitionVec(partitionVecY); 93 | poski_DestroyVec(x_view); 94 | poski_DestroyVec(y_view); 95 | poski_DestroyPartitionMat(partitionMat); 96 | poski_DestroyMat(A_tunable); 97 | poski_DestroyThreads(poski_thread); 98 | poski_Close(); 99 | } 100 | -------------------------------------------------------------------------------- /src/bench/PoskiModule.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file PoskiModule.hpp 11 | * \brief The SpMV kernel implemented with pOSKI 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef POSKI_MODULE_HPP 20 | #define POSKI_MODULE_HPP 21 | 22 | #include 23 | 24 | SPX_BEGIN_C_DECLS__ 25 | // Undefine HAVE_CONFIG_H, as if we were including poski normally 26 | #undef HAVE_CONFIG_H 27 | #include 28 | SPX_END_C_DECLS__ 29 | 30 | #include "Timer.hpp" 31 | #include 32 | #include 33 | 34 | void poski_spmv(spx_index_t *Aptr, spx_index_t *Aind, spx_value_t *Aval, 35 | spx_index_t nrows, spx_index_t ncols, spx_index_t nnz, 36 | spx_value_t *x, spx_value_t *y, 37 | spx_value_t ALPHA, spx_value_t BETA); 38 | 39 | #endif // POSKI_MODULE_HPP 40 | 41 | -------------------------------------------------------------------------------- /src/bench/SparsexModule.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file SparsexModule.cpp 11 | * \brief The SpMV kernel implemented with SparseX 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include "SparsexModule.hpp" 20 | #include 21 | #include 22 | 23 | using namespace std; 24 | 25 | extern string MATRIX; 26 | extern unsigned int OUTER_LOOPS; 27 | extern unsigned long LOOPS; 28 | extern Timer t; 29 | 30 | /* SpMV kernel implemented with SparseX */ 31 | void sparsex_spmv(spx_index_t *rowptr, spx_index_t *colind, spx_value_t *values, 32 | spx_index_t nrows, spx_index_t ncols, spx_index_t nnz, 33 | spx_value_t *x, spx_value_t *y, 34 | spx_value_t ALPHA, spx_value_t BETA) 35 | { 36 | spx_init(); 37 | spx_log_verbose_console(); 38 | 39 | /* 1. Matrix loading phase */ 40 | spx_input_t *input = spx_input_load_csr( 41 | rowptr, colind, values, nrows, ncols, SPX_INDEX_ZERO_BASED); 42 | 43 | /* 2. Tuning phase */ 44 | spx_options_set_from_env(); 45 | t.Clear(); 46 | t.Start(); 47 | spx_matrix_t *A = spx_mat_tune(input);//, SPX_MAT_REORDER); 48 | t.Pause(); 49 | spx_value_t pt = t.ElapsedTime(); 50 | 51 | /* 3. Vector loading */ 52 | spx_partition_t *parts = spx_mat_get_partition(A); 53 | spx_value_t *y_tuned; 54 | spx_vector_t *x_view = spx_vec_create_from_buff( 55 | x, NULL, ncols, parts, SPX_VEC_TUNE); 56 | spx_vector_t *y_view = spx_vec_create_from_buff( 57 | y, &y_tuned, nrows, parts, SPX_VEC_TUNE); 58 | 59 | /* Reorder vectors */ 60 | // spx_perm_t *p = spx_mat_get_perm(A); 61 | // spx_vec_reorder(x_view, p); 62 | // spx_vec_reorder(y_view, p); 63 | 64 | /* 4. SpMV benchmarking phase */ 65 | vector mt(OUTER_LOOPS); 66 | for (unsigned int i = 0; i < OUTER_LOOPS; i++) { 67 | t.Clear(); 68 | t.Start(); 69 | for (unsigned long int j = 0; j < LOOPS; j++) { 70 | spx_matvec_kernel(ALPHA, A, x_view, BETA, y_view); 71 | } 72 | t.Pause(); 73 | mt[i] = t.ElapsedTime(); 74 | } 75 | 76 | sort(mt.begin(), mt.end()); 77 | double mt_median = 78 | (OUTER_LOOPS % 2) ? mt[((OUTER_LOOPS+1)/2)-1] 79 | : ((mt[OUTER_LOOPS/2-1] + mt[OUTER_LOOPS/2])/2); 80 | double flops = (double)(LOOPS*nnz*2)/((double)1000*1000*mt_median); 81 | cout << "m: " << MATRIX 82 | << " pt: " << pt 83 | << " mt(median): " << mt_median 84 | << " flops: " << flops << endl; 85 | 86 | /* Restore original ordering of resulting vector */ 87 | // spx_vec_inv_reorder(y_view, p); 88 | // spx_vec_inv_reorder(x_view, p); 89 | 90 | if (y_tuned != y) { 91 | for (spx_index_t i = 0; i < nrows; i++) 92 | y[i] = y_tuned[i]; 93 | free(y_tuned); 94 | } 95 | 96 | /* 5. Cleanup */ 97 | spx_input_destroy(input); 98 | spx_mat_destroy(A); 99 | spx_partition_destroy(parts); 100 | spx_vec_destroy(x_view); 101 | spx_vec_destroy(y_view); 102 | } 103 | -------------------------------------------------------------------------------- /src/bench/SparsexModule.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file SparsexModule.hpp 11 | * \brief The SpMV kernel implemented with SparseX 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #ifndef SPARSEX_MODULE_HPP 20 | #define SPARSEX_MODULE_HPP 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #include "Timer.hpp" 33 | #include 34 | 35 | void sparsex_spmv(spx_index_t *rowptr, spx_index_t *colind, 36 | spx_value_t *values, spx_index_t nrows, 37 | spx_index_t ncols, spx_index_t nnz, 38 | spx_value_t *x, spx_value_t *y, 39 | spx_value_t ALPHA, spx_value_t BETA); 40 | 41 | #endif // SPARSEX_MODULE_HPP 42 | -------------------------------------------------------------------------------- /src/bench/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2013, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2010-2012, Vasileios Karakasis 4 | * Copyright (C) 2012-2013, Athena Elafrou 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file Timer.cpp 12 | * \brief Timing utilities 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include "Timer.hpp" 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | 26 | void Timer::Start() 27 | { 28 | if (gettimeofday(×tamp_, NULL) < 0) { 29 | cerr << "timer error: gettimeofday()" << endl; 30 | exit(1); 31 | } 32 | } 33 | 34 | void Timer::Pause() 35 | { 36 | struct timeval t_stop; 37 | struct timeval t_interval; 38 | 39 | if (gettimeofday(&t_stop, NULL) < 0) { 40 | cerr << "timer error: gettimeofday()" << endl; 41 | exit(1); 42 | } 43 | 44 | timersub(&t_stop, ×tamp_, &t_interval); 45 | timeradd(&elapsed_time_, &t_interval, &elapsed_time_); 46 | } 47 | 48 | void Timer::Stop() 49 | { 50 | Timer::Pause(); 51 | Timer::Clear(); 52 | } 53 | 54 | void Timer::Clear() 55 | { 56 | timerclear(&elapsed_time_); 57 | timerclear(×tamp_); 58 | } 59 | 60 | double Timer::ElapsedTime() 61 | { 62 | return (elapsed_time_.tv_sec + 63 | elapsed_time_.tv_usec / (double) 1000000);//USEC_PER_SEC 64 | } 65 | -------------------------------------------------------------------------------- /src/bench/Timer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2013, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2010-2012, Vasileios Karakasis 4 | * Copyright (C) 2012-2013, Athena Elafrou 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file Timer.hpp 12 | * \brief Timing utilities 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #ifndef TIMER_HPP 21 | #define TIMER_HPP 22 | 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | 28 | class Timer 29 | { 30 | public: 31 | 32 | Timer() 33 | : description_(), 34 | elapsed_time_(), 35 | timestamp_() 36 | { 37 | Clear(); 38 | } 39 | 40 | Timer(string desc) 41 | : description_(desc), 42 | elapsed_time_(), 43 | timestamp_() 44 | { 45 | Clear(); 46 | } 47 | 48 | Timer(const char *desc, const char *desc2) 49 | : description_((string) desc), 50 | elapsed_time_(), 51 | timestamp_() 52 | { 53 | Clear(); 54 | } 55 | 56 | ~Timer() {} 57 | 58 | void Start(); 59 | void Pause(); 60 | void Stop(); 61 | void Clear(); 62 | double ElapsedTime(); 63 | 64 | void SetDescription(const char *desc) 65 | { 66 | description_ = (string) desc; 67 | } 68 | 69 | void SetDescription(string desc) 70 | { 71 | description_ = desc; 72 | } 73 | 74 | string GetDescription() 75 | { 76 | return description_; 77 | } 78 | 79 | private: 80 | string description_; 81 | struct timeval elapsed_time_; 82 | struct timeval timestamp_; 83 | }; 84 | 85 | #endif //TIMER_HPP 86 | -------------------------------------------------------------------------------- /src/examples/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- Makefile for library benchmarks 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All rights reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | ACLOCAL_AMFLAGS = -I m4check 13 | 14 | AM_CPPFLAGS = \ 15 | -I$(top_builddir)/include \ 16 | -I$(top_srcdir)/include \ 17 | -I$(top_srcdir)/src/examples \ 18 | $(AX_CPPFLAGS) 19 | 20 | AM_CFLAGS = $(AX_CFLAGS) 21 | AM_CXXFLAGS = $(AX_CXXFLAGS) 22 | AM_LDFLAGS = \ 23 | -L$(top_builddir)/src/api/.libs \ 24 | $(AX_LDFLAGS) 25 | 26 | SPARSEX_LDADD = \ 27 | $(top_builddir)/src/api/.libs/libsparsex.la 28 | 29 | noinst_PROGRAMS = mmf_example csr_example reordering_example advanced_example matrix_caching_example_p1 matrix_caching_example_p2 30 | 31 | # Dummy C++ source to cause C++ linking. This is required becaused the 32 | # sublibraries include C++ source code, so we must force automake to select 33 | # the appropriate linker. 34 | nodist_EXTRA_mmf_example_SOURCES = dummy.cxx 35 | mmf_example_SOURCES = \ 36 | mmf_example.c 37 | mmf_example_LDFLAGS = -rpath $(LLVM_LIBDIR) 38 | mmf_example_LDADD = $(SPARSEX_LDADD) 39 | 40 | nodist_EXTRA_csr_example_SOURCES = dummy.cxx 41 | csr_example_SOURCES = \ 42 | csr_example.c 43 | csr_example_LDFLAGS = -rpath $(LLVM_LIBDIR) 44 | csr_example_LDADD = $(SPARSEX_LDADD) 45 | 46 | nodist_EXTRA_reordering_example_SOURCES = dummy.cxx 47 | reordering_example_SOURCES = \ 48 | reordering_example.c 49 | reordering_example_LDFLAGS = -rpath $(LLVM_LIBDIR) 50 | reordering_example_LDADD = $(SPARSEX_LDADD) 51 | 52 | nodist_EXTRA_advanced_example_SOURCES = dummy.cxx 53 | advanced_example_SOURCES = \ 54 | advanced_example.c 55 | advanced_example_LDFLAGS = -rpath $(LLVM_LIBDIR) 56 | advanced_example_LDADD = $(SPARSEX_LDADD) 57 | 58 | nodist_EXTRA_matrix_caching_example_p1_SOURCES = dummy.cxx 59 | matrix_caching_example_p1_SOURCES = \ 60 | matrix_caching_example_p1.c 61 | matrix_caching_example_p1_LDFLAGS = -rpath $(LLVM_LIBDIR) 62 | matrix_caching_example_p1_LDADD = $(SPARSEX_LDADD) 63 | 64 | nodist_EXTRA_matrix_caching_example_p2_SOURCES = dummy.cxx 65 | matrix_caching_example_p2_SOURCES = \ 66 | matrix_caching_example_p2.c 67 | matrix_caching_example_p2_LDFLAGS = -rpath $(LLVM_LIBDIR) 68 | matrix_caching_example_p2_LDADD = $(SPARSEX_LDADD) 69 | -------------------------------------------------------------------------------- /src/examples/advanced_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * Copyright (C) 2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file advanced_example.c 12 | * \brief This example shows usage of the vector tuning feature. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | static char *program_name; 24 | 25 | void print_usage() 26 | { 27 | fprintf(stderr, "Usage: %s \n", program_name); 28 | } 29 | 30 | int main(int argc, char **argv) 31 | { 32 | program_name = basename(argv[0]); 33 | 34 | /* Initialize library */ 35 | spx_init(); 36 | spx_log_info_console(); 37 | 38 | if (argc < 2) { 39 | fprintf(stderr, "%s: too few arguments\n", program_name); 40 | print_usage(); 41 | exit(1); 42 | } 43 | 44 | /* Load matrix from MMF file */ 45 | spx_input_t *input = spx_input_load_mmf(argv[1]); 46 | 47 | /* Set tuning options */ 48 | spx_option_set("spx.rt.nr_threads", "2"); 49 | spx_option_set("spx.rt.cpu_affinity", "0,1"); 50 | 51 | /* Transform to CSX */ 52 | spx_matrix_t *A = spx_mat_tune(input); 53 | 54 | /* Define random x and y arrays */ 55 | spx_index_t nrows = spx_mat_get_nrows(A); 56 | spx_index_t ncols = spx_mat_get_ncols(A); 57 | spx_value_t *x = (spx_value_t *) malloc(sizeof(spx_value_t) * ncols); 58 | spx_value_t *y = (spx_value_t *) malloc(sizeof(spx_value_t) * nrows); 59 | spx_value_t val = 0, max = 1, min = -1; 60 | size_t i; 61 | for (i = 0; i < nrows; i++) { 62 | val = ((spx_value_t) (rand()+i) / ((spx_value_t) RAND_MAX + 1)); 63 | x[i] = min + val*(max-min); 64 | y[i] = max + val*(min-max); 65 | } 66 | 67 | /* Create x and y vectors from the corresponding buffers */ 68 | spx_value_t *x_tuned, *y_tuned; 69 | spx_partition_t *parts = spx_mat_get_partition(A); 70 | spx_vector_t *x_view = spx_vec_create_from_buff( 71 | x, &x_tuned, ncols, parts, SPX_VEC_TUNE); 72 | spx_vector_t *y_view = spx_vec_create_from_buff( 73 | y, &y_tuned, nrows, parts, SPX_VEC_TUNE); 74 | 75 | /* Run 128 loops of the SpMV kernel */ 76 | spx_value_t alpha = 0.8, beta = 0.42; 77 | const size_t nr_loops = 128; 78 | spx_timer_t t; 79 | double elapsed_time, flops; 80 | 81 | spx_timer_clear(&t); 82 | spx_timer_start(&t); 83 | for (i = 0; i < nr_loops; i++) { 84 | spx_matvec_kernel(alpha, A, x_view, beta, y_view); 85 | } 86 | spx_timer_pause(&t); 87 | elapsed_time = spx_timer_get_secs(&t); 88 | flops = (double) (2 * nr_loops * spx_mat_get_nnz(A)) / 89 | ((double) 1000 * 1000 * elapsed_time); 90 | printf("SPMV time: %lf secs\n", elapsed_time); 91 | printf("MFLOPS: %lf\n", flops); 92 | 93 | /* From this point on the user can use the tuned buffers */ 94 | if (x_tuned != x) { 95 | x = x_tuned; 96 | } 97 | 98 | if (y_tuned != y) { 99 | y = y_tuned; 100 | } 101 | 102 | /* ... */ 103 | /* ... */ 104 | /* ... */ 105 | 106 | /* Cleanup */ 107 | spx_input_destroy(input); 108 | spx_mat_destroy(A); 109 | spx_partition_destroy(parts); 110 | spx_vec_destroy(x_view); 111 | spx_vec_destroy(y_view); 112 | 113 | /* The user can apply the free() function on the tuned buffers */ 114 | free(x); 115 | free(y); 116 | 117 | /* Shutdown library */ 118 | spx_finalize(); 119 | 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /src/examples/csr_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file csr_example.c 11 | * \brief Read matrix from the CSR format and tune it into the CSX format. This 12 | * example uses the spx_mat_vec_kernel_csr() routine that hides the 13 | * preprocessing phase of CSX. 14 | * 15 | * \author Computing Systems Laboratory (CSLab), NTUA 16 | * \date 2011–2014 17 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 18 | * for details. 19 | */ 20 | 21 | #include 22 | 23 | int main(int argc, char **argv) 24 | { 25 | /* Define CSR data structures */ 26 | spx_index_t nrows = 10, ncols = 10; 27 | spx_index_t rowptr[] = {0,5,6,10,15,18,22,24,29,33,38}; 28 | spx_index_t colind[] = {0,1,2,3,8,7,0,1,6,9,0,1,3,5,9,0,1,9,0,1,5,9,2,3, 29 | 2,3,4,5,7,2,3,4,5,2,3,4,5,9}; 30 | spx_value_t values[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 31 | 20,21,22,23,24,25,26,26.1,26.2,27,28,29,29.1,29.2, 32 | 30,31,31.1,31.2,32}; 33 | 34 | /* Initialize library */ 35 | spx_init(); 36 | spx_log_info_console(); 37 | 38 | /* Partition input matrix */ 39 | spx_partition_t *parts = spx_partition_csr(rowptr, nrows, 2); 40 | 41 | /* Create random x and y vectors */ 42 | spx_vector_t *x = spx_vec_create_random(nrows, parts); 43 | spx_vector_t *y = spx_vec_create_random(nrows, parts); 44 | 45 | /* Declare a tuned matrix handle */ 46 | spx_matrix_t *A = SPX_INVALID_MAT; 47 | 48 | /* Set tuning options */ 49 | spx_option_set("spx.rt.nr_threads", "2"); 50 | spx_option_set("spx.rt.cpu_affinity", "0,1"); 51 | 52 | /* Transform to CSX and run the SpMV kernel */ 53 | spx_value_t alpha = 0.8, beta = 0.42; 54 | const size_t nr_loops = 1500; 55 | size_t i; 56 | spx_timer_t t; 57 | double elapsed_time, flops; 58 | 59 | spx_timer_clear(&t); 60 | spx_timer_start(&t); 61 | for (i = 0; i < nr_loops; i++) { 62 | spx_matvec_kernel_csr(&A, nrows, ncols, rowptr, colind, values, 63 | alpha, x, beta, y); 64 | } 65 | spx_timer_pause(&t); 66 | 67 | elapsed_time = spx_timer_get_secs(&t); 68 | flops = (double) (2 * nr_loops * spx_mat_get_nnz(A)) / 69 | ((double) 1000 * 1000 * elapsed_time); 70 | printf("SPMV time: %lf secs\n", elapsed_time); 71 | printf("MFLOPS: %lf\n", flops); 72 | 73 | /* Cleanup */ 74 | spx_mat_destroy(A); 75 | spx_partition_destroy(parts); 76 | spx_vec_destroy(x); 77 | spx_vec_destroy(y); 78 | 79 | /* Shutdown library */ 80 | spx_finalize(); 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /src/examples/matrix_caching_example_p1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * Copyright (C) 2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file matrix_caching_example_p1.c 12 | * \brief Read matrix from MMF file, tune it into the CSX format and save it 13 | * in a binary file for a future session. 14 | * 15 | * \author Computing Systems Laboratory (CSLab), NTUA 16 | * \date 2011–2014 17 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 18 | * for details. 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | static char *program_name; 25 | 26 | void print_usage() 27 | { 28 | fprintf(stderr, "Usage: %s \n", program_name); 29 | } 30 | 31 | int main(int argc, char **argv) 32 | { 33 | program_name = basename(argv[0]); 34 | 35 | /* Initialize library */ 36 | spx_init(); 37 | spx_log_info_console(); 38 | 39 | if (argc < 3) { 40 | fprintf(stderr, "%s: too few arguments\n", program_name); 41 | print_usage(); 42 | exit(1); 43 | } 44 | 45 | /* Load matrix from MMF file */ 46 | spx_input_t *input = spx_input_load_mmf(argv[1]); 47 | 48 | /* Set tuning options */ 49 | spx_option_set("spx.rt.nr_threads", "2"); 50 | spx_option_set("spx.rt.cpu_affinity", "0,1"); 51 | 52 | /* Transform to CSX */ 53 | spx_matrix_t *A = spx_mat_tune(input); 54 | 55 | /* Save matrix in a binary file for future session */ 56 | spx_mat_save(A, argv[2]); 57 | 58 | /* Create random x and y vectors */ 59 | spx_partition_t *parts = spx_mat_get_partition(A); 60 | spx_vector_t *x = spx_vec_create_random(spx_mat_get_ncols(A), parts); 61 | spx_vector_t *y = spx_vec_create_random(spx_mat_get_nrows(A), parts); 62 | 63 | /* Run 128 loops of the SpMV kernel */ 64 | spx_value_t alpha = 0.8, beta = 0.42; 65 | const size_t nr_loops = 128; 66 | spx_timer_t t; 67 | double elapsed_time, flops; 68 | size_t i; 69 | 70 | spx_timer_clear(&t); 71 | spx_timer_start(&t); 72 | for (i = 0; i < nr_loops; i++) { 73 | spx_matvec_kernel(alpha, A, x, beta, y); 74 | } 75 | spx_timer_pause(&t); 76 | 77 | elapsed_time = spx_timer_get_secs(&t); 78 | flops = (double) (2 * nr_loops * spx_mat_get_nnz(A)) / 79 | ((double) 1000 * 1000 * elapsed_time); 80 | printf("SPMV time: %lf secs\n", elapsed_time); 81 | printf("MFLOPS: %lf\n", flops); 82 | 83 | /* Cleanup */ 84 | spx_input_destroy(input); 85 | spx_mat_destroy(A); 86 | spx_partition_destroy(parts); 87 | spx_vec_destroy(x); 88 | spx_vec_destroy(y); 89 | 90 | /* Shutdown library */ 91 | spx_finalize(); 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /src/examples/matrix_caching_example_p2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * Copyright (C) 2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file matrix_caching_example_p2.c 12 | * \brief Read CSX matrix from a binary file. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | static char *program_name; 24 | 25 | void print_usage() 26 | { 27 | fprintf(stderr, "Usage: %s \n", program_name); 28 | } 29 | 30 | int main(int argc, char **argv) 31 | { 32 | program_name = basename(argv[0]); 33 | 34 | /* Initialize library */ 35 | spx_init(); 36 | spx_log_info_console(); 37 | 38 | if (argc < 2) { 39 | fprintf(stderr, "%s: too few arguments\n", program_name); 40 | print_usage(); 41 | exit(1); 42 | } 43 | 44 | /* Load matrix from binary file */ 45 | spx_matrix_t *A = spx_mat_restore(argv[1]); 46 | 47 | /* Change some values in the matrix */ 48 | spx_index_t row = 1, col = 1; 49 | spx_value_t value = 0.42; 50 | spx_mat_set_entry(A, row, col, value); 51 | /* ... */ 52 | 53 | /* Create random x and y vectors */ 54 | spx_partition_t *parts = spx_mat_get_partition(A); 55 | spx_vector_t *x = spx_vec_create_random(spx_mat_get_ncols(A), parts); 56 | spx_vector_t *y = spx_vec_create_random(spx_mat_get_nrows(A), parts); 57 | 58 | /* Run 128 loops of the SpMV kernel */ 59 | spx_value_t alpha = 0.8, beta = 0.42; 60 | const size_t nr_loops = 128; 61 | spx_timer_t t; 62 | double elapsed_time, flops; 63 | size_t i; 64 | 65 | spx_timer_clear(&t); 66 | spx_timer_start(&t); 67 | for (i = 0; i < nr_loops; i++) { 68 | spx_matvec_kernel(alpha, A, x, beta, y); 69 | } 70 | spx_timer_pause(&t); 71 | 72 | elapsed_time = spx_timer_get_secs(&t); 73 | flops = (double) (2 * nr_loops * spx_mat_get_nnz(A)) / 74 | ((double) 1000 * 1000 * elapsed_time); 75 | printf("SPMV time: %lf secs\n", elapsed_time); 76 | printf("MFLOPS: %lf\n", flops); 77 | 78 | /* Cleanup */ 79 | spx_mat_destroy(A); 80 | spx_partition_destroy(parts); 81 | spx_vec_destroy(x); 82 | spx_vec_destroy(y); 83 | 84 | /* Shutdown library */ 85 | spx_finalize(); 86 | 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /src/examples/mmf_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * Copyright (C) 2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file mmf_example.c 12 | * \brief Read matrix from MMF file and tune it into the CSX format. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | static char *program_name; 24 | 25 | void print_usage() 26 | { 27 | fprintf(stderr, "Usage: %s \n", program_name); 28 | } 29 | 30 | int main(int argc, char **argv) 31 | { 32 | program_name = basename(argv[0]); 33 | 34 | /* Initialize library */ 35 | spx_init(); 36 | spx_log_info_console(); 37 | 38 | if (argc < 2) { 39 | fprintf(stderr, "%s: too few arguments\n", program_name); 40 | print_usage(); 41 | exit(1); 42 | } 43 | 44 | /* Load matrix from MMF file */ 45 | spx_input_t *input = spx_input_load_mmf(argv[1]); 46 | 47 | /* Set tuning options */ 48 | spx_option_set("spx.rt.nr_threads", "2"); 49 | spx_option_set("spx.rt.cpu_affinity", "0,1"); 50 | /* spx_option_set("spx.matrix.symmetric", "true"); */ 51 | 52 | /* Transform to CSX */ 53 | spx_matrix_t *A = spx_mat_tune(input); 54 | 55 | /* Create random x and y vectors */ 56 | spx_partition_t *parts = spx_mat_get_partition(A); 57 | spx_vector_t *x = spx_vec_create_random(spx_mat_get_ncols(A), parts); 58 | spx_vector_t *y = spx_vec_create_random(spx_mat_get_nrows(A), parts); 59 | 60 | /* Run 128 loops of the SpMV kernel */ 61 | spx_value_t alpha = 0.8, beta = 0.42; 62 | const size_t nr_loops = 128; 63 | spx_timer_t t; 64 | double elapsed_time, flops; 65 | size_t i; 66 | 67 | spx_timer_clear(&t); 68 | spx_timer_start(&t); 69 | for (i = 0; i < nr_loops; i++) { 70 | spx_matvec_kernel(alpha, A, x, beta, y); 71 | } 72 | spx_timer_pause(&t); 73 | 74 | elapsed_time = spx_timer_get_secs(&t); 75 | flops = (double) (2 * nr_loops * spx_mat_get_nnz(A)) / 76 | ((double) 1000 * 1000 * elapsed_time); 77 | printf("SPMV time: %lf secs\n", elapsed_time); 78 | printf("MFLOPS: %lf\n", flops); 79 | 80 | /* Cleanup */ 81 | spx_input_destroy(input); 82 | spx_mat_destroy(A); 83 | spx_partition_destroy(parts); 84 | spx_vec_destroy(x); 85 | spx_vec_destroy(y); 86 | 87 | /* Shutdown library */ 88 | spx_finalize(); 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /src/examples/reordering_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file reordering_example.c 11 | * \brief Example thats applies reordering to the input matrix and uses the 12 | * symmetrix variant of CSX. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | static char *program_name; 24 | 25 | void print_usage() 26 | { 27 | fprintf(stderr, "Usage: %s \n", basename(program_name)); 28 | } 29 | 30 | int main(int argc, char **argv) 31 | { 32 | program_name = argv[0]; 33 | 34 | /* Initialize library */ 35 | spx_init(); 36 | spx_log_info_console(); 37 | 38 | if (argc < 2) { 39 | fprintf(stderr, "%s: too few arguments\n", program_name); 40 | print_usage(); 41 | exit(1); 42 | } 43 | 44 | /* Load matrix from MMF file */ 45 | spx_input_t *input = spx_input_load_mmf(argv[1]); 46 | 47 | /* Set tuning options */ 48 | spx_option_set("spx.rt.nr_threads", "2"); 49 | spx_option_set("spx.rt.cpu_affinity", "0,1"); 50 | spx_option_set("spx.matrix.symmetric", "true"); 51 | 52 | /* Transform to CSX with reordering enabled */ 53 | spx_matrix_t *A = spx_mat_tune(input, SPX_MAT_REORDER); 54 | 55 | /* Create random x and y vectors */ 56 | spx_partition_t *parts = spx_mat_get_partition(A); 57 | spx_vector_t *x = spx_vec_create_random(spx_mat_get_ncols(A), parts); 58 | spx_vector_t *y = spx_vec_create_random(spx_mat_get_nrows(A), parts); 59 | 60 | /* Reorder vectors */ 61 | spx_perm_t *p = spx_mat_get_perm(A); 62 | spx_vec_reorder(x, p); 63 | spx_vec_reorder(y, p); 64 | 65 | /* Run 128 loops of the SpMV kernel */ 66 | spx_value_t alpha = 0.8, beta = 0.42; 67 | const size_t nr_loops = 128; 68 | spx_timer_t t; 69 | double elapsed_time, flops; 70 | size_t i; 71 | 72 | spx_timer_clear(&t); 73 | spx_timer_start(&t); 74 | for (i = 0; i < nr_loops; i++) { 75 | spx_matvec_kernel(alpha, A, x, beta, y); 76 | } 77 | spx_timer_pause(&t); 78 | 79 | elapsed_time = spx_timer_get_secs(&t); 80 | flops = (double) (2 * nr_loops * spx_mat_get_nnz(A)) / 81 | ((double) 1000 * 1000 * elapsed_time); 82 | printf("SPMV time: %lf secs\n", elapsed_time); 83 | printf("MFLOPS: %lf\n", flops); 84 | 85 | /* Restore original ordering of resulting vector */ 86 | spx_vec_inv_reorder(y, p); 87 | 88 | /* Cleanup */ 89 | spx_input_destroy(input); 90 | spx_mat_destroy(A); 91 | spx_partition_destroy(parts); 92 | spx_vec_destroy(x); 93 | spx_vec_destroy(y); 94 | 95 | /* Shutdown library */ 96 | spx_finalize(); 97 | 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /src/internals/Affinity.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2014, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2007-2011, Kornilios Kourtis 4 | * Copyright (C) 2013-2014, Athena Elafrou 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file Affinity.cpp 12 | * \brief Routine that sets the cpu affinity 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace sparsex { 26 | namespace runtime { 27 | 28 | void setaffinity_oncpu(unsigned int cpu) 29 | { 30 | cpu_set_t cpu_mask; 31 | 32 | CPU_ZERO(&cpu_mask); 33 | CPU_SET(cpu, &cpu_mask); 34 | 35 | int err = sched_setaffinity(0, sizeof(cpu_set_t), &cpu_mask); 36 | if (err) { 37 | LOG_ERROR << "sched_setaffinity failed\n"; 38 | exit(1); 39 | } 40 | } 41 | 42 | int get_cpu_count() 43 | { 44 | cpu_set_t cpu_mask; 45 | 46 | CPU_ZERO(&cpu_mask); 47 | int err = sched_getaffinity(0, sizeof(cpu_set_t), &cpu_mask); 48 | if (err) { 49 | LOG_ERROR << "sched_getaffinity failed\n"; 50 | exit(1); 51 | } 52 | 53 | int count = CPU_COUNT(&cpu_mask); 54 | printf("%d\n", count); 55 | 56 | return count; 57 | } 58 | 59 | } // end of namespace runtime 60 | } // end of namespace sparsex 61 | -------------------------------------------------------------------------------- /src/internals/Barrier.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Barrier.cpp 11 | * \brief A centralized barrier with timeout 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | 21 | using namespace std; 22 | 23 | namespace sparsex { 24 | namespace runtime { 25 | 26 | atomic global_sense; 27 | atomic barrier_cnt; 28 | 29 | static inline int do_spin(int *local_sense) 30 | { 31 | volatile int i, spin_cnt = BARRIER_TIMEOUT; 32 | 33 | for (i = 0; i < spin_cnt; i++) { 34 | if ((*local_sense) == global_sense.load()) { 35 | return 0; 36 | } else { 37 | __asm volatile ("" : : : "memory"); 38 | } 39 | } 40 | 41 | return 1; 42 | } 43 | 44 | void centralized_barrier(int *local_sense, size_t nr_threads) 45 | { 46 | // each processor toggles its own sense 47 | *local_sense = !(*local_sense); 48 | if (atomic_fetch_sub(&barrier_cnt, 1) == 1) { 49 | barrier_cnt.store(nr_threads); 50 | // last processor toggles global sense 51 | global_sense.store(*local_sense); 52 | // wake up the other threads 53 | futex_wake((int *) &global_sense, nr_threads); 54 | } else { 55 | while (*local_sense != global_sense.load()) { 56 | if (do_spin(local_sense)) 57 | futex_wait((int *) &global_sense, !(*local_sense)); 58 | } 59 | } 60 | } 61 | 62 | } // end of namespace runtime 63 | } // end of namespace sparsex 64 | -------------------------------------------------------------------------------- /src/internals/CodeExecutor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2017, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file CodeExecutor.cpp 11 | * \brief Component that dynamically loads a compiled module in memory for 12 | execution based on LLVM. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2017 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | 22 | using namespace std; 23 | 24 | namespace sparsex { 25 | namespace jit { 26 | 27 | CodeExecutor::CodeExecutor() 28 | : engine_(nullptr) 29 | { 30 | LLVMInitializeNativeTarget(); 31 | LLVMInitializeNativeAsmPrinter(); 32 | LLVMInitializeNativeAsmParser(); 33 | LLVMLinkInMCJIT(); 34 | } 35 | 36 | CodeExecutor::~CodeExecutor() 37 | { 38 | // check if engine contains modules delete them/remove them? 39 | delete engine_; 40 | delete builder_; 41 | llvm::llvm_shutdown(); 42 | } 43 | 44 | void CodeExecutor::AddModule(unique_ptr module) 45 | { 46 | // The ExecutionEngine takes ownership of the module 47 | if (!engine_) { 48 | string errmsg; 49 | builder_ = new llvm::EngineBuilder(move(module)); 50 | builder_->setErrorStr(&errmsg); 51 | builder_->setEngineKind(llvm::EngineKind::JIT); 52 | builder_->setVerifyModules(true); 53 | engine_ = builder_->create(); 54 | if (!engine_) { 55 | cerr << "[ERROR]: failed to create LLVM execution engine, " 56 | << errmsg 57 | << endl; 58 | exit(1); 59 | } 60 | } else { 61 | engine_->addModule(move(module)); 62 | } 63 | 64 | assert(module.get() == nullptr); 65 | // Code generation is deferred here 66 | engine_->finalizeObject(); 67 | } 68 | 69 | void CodeExecutor::RemoveModule(llvm::Module *module) 70 | { 71 | engine_->removeModule(module); 72 | } 73 | 74 | uint64_t CodeExecutor::GetFnAddress(const string func_name) 75 | { 76 | // Resolves name mangling for C++ code 77 | return engine_->getFunctionAddress(func_name); 78 | } 79 | 80 | } // end of namespace jit 81 | } // end of namespace sparsex 82 | -------------------------------------------------------------------------------- /src/internals/CsxBuild.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2012, Vasileios Karakasis 4 | * Copyright (C) 2011-2012, Theodoros Gkountouvas 5 | * Copyright (C) 2013-2014, Athena Elafrou 6 | * All rights reserved. 7 | * 8 | * This file is distributed under the BSD License. See LICENSE.txt for details. 9 | */ 10 | 11 | /** 12 | * \file CsxBuild.cpp 13 | * \brief Front-end utilities for building CSX 14 | * 15 | * \author Computing Systems Laboratory (CSLab), NTUA 16 | * \date 2011–2014 17 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 18 | * for details. 19 | */ 20 | 21 | #include 22 | 23 | namespace sparsex { 24 | namespace csx { 25 | 26 | spm_mt_t *PrepareSpmMt() 27 | { 28 | spm_mt_t *spm_mt; 29 | RtConfig &rt_config = RtConfig::GetInstance(); 30 | RtCtx &rt_context = RtCtx::GetInstance(); 31 | 32 | spm_mt = new spm_mt_t; 33 | spm_mt->nr_threads = rt_context.GetNrThreads(); 34 | spm_mt->local_buffers = NULL; 35 | #if SPX_USE_NUMA 36 | spm_mt->interleaved = false; 37 | #endif 38 | spm_mt->symmetric = 39 | rt_config.GetProperty(RtConfig::MatrixSymmetric); 40 | spm_mt->spm_threads = new spm_mt_thread_t[rt_context.GetNrThreads()]; 41 | for (size_t i = 0; i < rt_context.GetNrThreads(); i++) { 42 | spm_mt->spm_threads[i].cpu = rt_context.GetAffinity(i); 43 | spm_mt->spm_threads[i].node = 44 | numa_node_of_cpu(rt_context.GetAffinity(i)); 45 | spm_mt->spm_threads[i].id = i; 46 | spm_mt->spm_threads[i].sense = 0; 47 | } 48 | 49 | return spm_mt; 50 | } 51 | 52 | } // end of namespace csx 53 | } // end of namespace sparsex 54 | -------------------------------------------------------------------------------- /src/internals/CsxSpmv.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2012-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file CsxSpmv.cpp 11 | * \brief Thread-level SpMV routines 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | 21 | using namespace sparsex::runtime; 22 | 23 | extern vector_t **temp; 24 | extern size_t nr_threads; 25 | 26 | namespace sparsex { 27 | 28 | void do_mv_thread(void *args) 29 | { 30 | spm_mt_thread_t *spm_thread = (spm_mt_thread_t *) args; 31 | spmv_fn_t fn = spm_thread->spmv_fn; 32 | double ALPHA = spm_thread->alpha; 33 | 34 | fn(spm_thread->csx, spm_thread->x, spm_thread->y, ALPHA, NULL); 35 | } 36 | 37 | void do_mv_sym_thread(void *args) 38 | { 39 | spm_mt_thread_t *spm_thread = (spm_mt_thread_t *) args; 40 | spmv_fn_t fn = spm_thread->spmv_fn; 41 | double ALPHA = spm_thread->alpha; 42 | int id = spm_thread->id; 43 | 44 | VecInitFromMap(temp, 0, spm_thread->map); 45 | centralized_barrier(&(spm_thread->sense), nr_threads); 46 | fn(spm_thread->csx, spm_thread->x, spm_thread->y, ALPHA, temp[id]); 47 | centralized_barrier(&(spm_thread->sense), nr_threads); 48 | /* Switch Reduction Phase */ 49 | VecAddFromMap(spm_thread->y, temp, spm_thread->y, spm_thread->map); 50 | } 51 | 52 | void do_kernel_thread(void *args) 53 | { 54 | spm_mt_thread_t *spm_thread = (spm_mt_thread_t *) args; 55 | spmv_fn_t fn = spm_thread->spmv_fn; 56 | double ALPHA = spm_thread->alpha; 57 | double BETA = spm_thread->beta; 58 | int start = spm_thread->row_start; 59 | int end = start + spm_thread->nr_rows; 60 | 61 | if (BETA != 1) 62 | VecScalePart(spm_thread->y, spm_thread->y, BETA, start, end); 63 | 64 | fn(spm_thread->csx, spm_thread->x, spm_thread->y, ALPHA, NULL); 65 | } 66 | 67 | void do_kernel_sym_thread(void *args) 68 | { 69 | spm_mt_thread_t *spm_thread = (spm_mt_thread_t *) args; 70 | spmv_fn_t fn = spm_thread->spmv_fn; 71 | double ALPHA = spm_thread->alpha; 72 | double BETA = spm_thread->beta; 73 | int start = spm_thread->row_start; 74 | int end = start + spm_thread->nr_rows; 75 | int id = spm_thread->id; 76 | 77 | VecInitFromMap(temp, 0, spm_thread->map); 78 | centralized_barrier(&(spm_thread->sense), nr_threads); 79 | if (BETA != 1) 80 | VecScalePart(spm_thread->y, spm_thread->y, BETA, start, end); 81 | 82 | fn(spm_thread->csx, spm_thread->x, spm_thread->y, ALPHA, temp[id]); 83 | centralized_barrier(&(spm_thread->sense), nr_threads); 84 | /* Switch Reduction Phase */ 85 | VecAddFromMap(spm_thread->y, temp, spm_thread->y, spm_thread->map); 86 | } 87 | 88 | } // end of namespace sparsex 89 | -------------------------------------------------------------------------------- /src/internals/CsxUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * Copyright (C) 2011-2012, Theodoros Gkountouvas 6 | * Copyright (C) 2013-2014, Athena Elafrou 7 | * All rights reserved. 8 | * 9 | * This file is distributed under the BSD License. See LICENSE.txt for details. 10 | */ 11 | 12 | /** 13 | * \file CsxUtil.cpp 14 | * \brief CSX-related utilities 15 | * 16 | * \author Computing Systems Laboratory (CSLab), NTUA 17 | * \date 2011–2014 18 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 19 | * for details. 20 | */ 21 | 22 | #include 23 | 24 | namespace sparsex { 25 | namespace csx { 26 | 27 | const unsigned long DeltaIdOffset = 0; 28 | const unsigned long PatternIdOffset = 10000; 29 | 30 | unsigned long GetPatternId(size_t delta_size) 31 | { 32 | return (delta_size << 3) + DeltaIdOffset; 33 | } 34 | 35 | } // end of namespace csx 36 | } // end of namespace sparsex 37 | -------------------------------------------------------------------------------- /src/internals/CtlBuilder.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file CtlBuilder.cpp 11 | * \brief Utility class for building the CSX's ctl structure 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | namespace sparsex { 23 | namespace csx { 24 | 25 | static inline void SetBit(uint8_t *byte, int bit) 26 | { 27 | assert(bit >= 0); 28 | assert(bit < 8); 29 | *byte |= (1<>= shift; 47 | } 48 | } 49 | 50 | void CtlBuilder::AppendFixedInt(unsigned long val, size_t nr_bytes) 51 | { 52 | assert(nr_bytes <= sizeof(val)); 53 | #ifdef PTR_ALIGN 54 | AlignCtl(nr_bytes); 55 | #endif 56 | for (size_t i = 0; i < nr_bytes; ++i) { 57 | uint8_t byte = *((uint8_t *) &val + i); 58 | ctl_da_.Append(byte); 59 | } 60 | } 61 | 62 | void CtlBuilder::AppendCtlHead(bool nr, size_t rowjmp, uint8_t id, 63 | uint8_t size, size_t ucol, size_t ucol_size, 64 | bool full_colind) 65 | { 66 | uint8_t flag = id; 67 | if (nr) 68 | SetBit(&flag, CTL_NR_BIT); 69 | if (rowjmp) 70 | SetBit(&flag, CTL_RJMP_BIT); 71 | 72 | ctl_da_.Append(flag); 73 | ctl_da_.Append(size); 74 | if (rowjmp) 75 | AppendVariableInt(rowjmp); 76 | 77 | if (full_colind) 78 | AppendFixedInt(ucol, ucol_size); 79 | else 80 | AppendVariableInt(ucol); 81 | } 82 | 83 | void CtlBuilder::AlignCtl(size_t boundary) 84 | { 85 | // Explicit padding must be added to ensure right pointer alignment 86 | // when ctl is dereferenced by the SpMV routine 87 | const uint8_t *elems = ctl_da_.GetElems(); 88 | const uint8_t *next = &elems[ctl_da_.GetSize()]; 89 | size_t nr_padd = (boundary - ((size_t) next & (boundary-1))) & 90 | (boundary-1); 91 | for (size_t i = 0; i < nr_padd; ++i) 92 | ctl_da_.Append(0); 93 | } 94 | 95 | } // end of namespace csx 96 | } // end of namespace sparsex 97 | -------------------------------------------------------------------------------- /src/internals/JitUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file JitUtil.cpp 11 | * \brief Jit-related utility functions 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | 28 | namespace sparsex { 29 | namespace jit { 30 | 31 | string SourceFromFile(const char *filename) 32 | { 33 | ifstream ifs(filename); 34 | string ret; 35 | for(;;) { 36 | char c = ifs.get(); 37 | if (!ifs.good()) 38 | break; 39 | ret.push_back(c); 40 | } 41 | 42 | ifs.close(); 43 | return ret; 44 | } 45 | 46 | string SourceFromFile(const string &filename) 47 | { 48 | return SourceFromFile(filename.c_str()); 49 | } 50 | 51 | void SourceToFile(const char *filename, const string &source) 52 | { 53 | ofstream ofs(filename); 54 | ofs << source; 55 | ofs.close(); 56 | } 57 | 58 | void SourceToFile(const string &filename, const string &source) 59 | { 60 | SourceToFile(filename.c_str(), source); 61 | } 62 | 63 | void RemoveFile(const char *path) 64 | { 65 | if (remove(path) < 0) { 66 | perror("RemoveFile()"); 67 | exit(1); 68 | } 69 | } 70 | 71 | const char *UniqueFilename(string &tmpl) 72 | { 73 | // Cannot play with C++ strings here, since mkstemp() alters is char * 74 | // argument 75 | char *local_tmpl = new char[tmpl.size()+1]; 76 | int fd; 77 | 78 | tmpl.copy(local_tmpl, tmpl.size()); 79 | local_tmpl[tmpl.size()] = '\0'; 80 | 81 | fd = mkstemp(local_tmpl); 82 | if (fd < 0) { 83 | perror("mkstemp() failed"); 84 | exit(1); 85 | } 86 | 87 | // close file descriptor and let the caller open the file in the C++ way 88 | // FIXME: an implementation with boost iostreams would be more portable 89 | close(fd); 90 | tmpl.assign(local_tmpl); 91 | delete[] local_tmpl; 92 | return tmpl.c_str(); 93 | } 94 | 95 | string Tabify(int num) 96 | { 97 | stringstream ss; 98 | 99 | for (int i = 0; i < num; i++) 100 | ss << "\t"; 101 | 102 | return ss.str(); 103 | } 104 | 105 | } // end of namespace jit 106 | } // end of namespace sparsex 107 | -------------------------------------------------------------------------------- /src/internals/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- SparseX library 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All rights reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AUTOMAKE_OPTIONS = subdir-objects 12 | AM_DEFAULT_VERBOSITY = 0 13 | ACLOCAL_AMFLAGS = -I m4check 14 | 15 | AM_CPPFLAGS = \ 16 | -I$(top_builddir)/include \ 17 | -I$(top_srcdir)/include \ 18 | $(AX_CPPFLAGS) \ 19 | $(LLVM_CPPFLAGS) 20 | 21 | AM_CFLAGS = $(AX_CFLAGS) 22 | AM_CXXFLAGS = $(AX_CXXFLAGS) 23 | AM_LDFLAGS = $(AX_LDFLAGS) 24 | 25 | lib_LTLIBRARIES = libsparseximpl.la 26 | libsparseximpl_la_SOURCES = \ 27 | futex.c \ 28 | numa_util.c \ 29 | Affinity.cpp \ 30 | Barrier.cpp \ 31 | CodeExecutor.cpp \ 32 | CsxBuild.cpp \ 33 | CsxKernels.cpp \ 34 | CsxSpmv.cpp \ 35 | CsxUtil.cpp \ 36 | CtlBuilder.cpp \ 37 | Encodings.cpp \ 38 | Facade.cpp \ 39 | JitCompiler.cpp \ 40 | JitUtil.cpp \ 41 | Mmf.cpp \ 42 | Node.cpp \ 43 | Runtime.cpp \ 44 | Statistics.cpp \ 45 | TemplateText.cpp \ 46 | ThreadPool.cpp \ 47 | Timer.cpp \ 48 | TimerCollection.cpp \ 49 | Vector.cpp \ 50 | logger/Logger.cpp \ 51 | logger/OutputPolicy.cpp 52 | 53 | libsparseximpl_la_LIBADD = \ 54 | $(BOOST_REGEX_LIB) \ 55 | $(BOOST_SERIALIZATION_LIB) \ 56 | $(BOOST_SYSTEM_LIB) \ 57 | $(BOOST_ATOMIC_LIB) \ 58 | $(CLANG_LIBS) \ 59 | $(LLVM_LIBS) \ 60 | $(LLVM_SYSTEM_LIBS) 61 | -------------------------------------------------------------------------------- /src/internals/Mmf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011, Vasileios Karakasis 5 | * Copyright (C) 2011, Theodoros Gkountouvas 6 | * Copyright (C) 2012-2013, Athena Elafrou 7 | * All rights reserved. 8 | * 9 | * This file is distributed under the BSD License. See LICENSE.txt for details. 10 | */ 11 | 12 | /** 13 | * \file Mmf.cpp 14 | * \brief Matrix Market Format utilities 15 | * 16 | * \author Computing Systems Laboratory (CSLab), NTUA 17 | * \date 2011–2014 18 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 19 | * for details. 20 | */ 21 | 22 | #include 23 | 24 | namespace sparsex { 25 | namespace io { 26 | 27 | // For testing purposes 28 | void ReadMmfSizeLine(const char *mmf_file, size_t &nr_rows, size_t &nr_cols, 29 | size_t &nr_nzeros) 30 | { 31 | ifstream in; 32 | 33 | try { 34 | in.open(mmf_file); 35 | if (!in.is_open()) { 36 | throw ios_base::failure(""); 37 | } 38 | in.seekg(0, ios::beg); 39 | // Ignore comments 40 | while (in.peek() == '%') { 41 | in.ignore(numeric_limits::max(), '\n'); 42 | } 43 | } catch (ios_base::failure &e) { 44 | LOG_ERROR << "MMF file error\n"; 45 | exit(1); 46 | } 47 | 48 | vector arguments; 49 | if (!(DoRead(in, arguments))) { 50 | LOG_ERROR << "size line error in MMF file\n"; 51 | exit(1); 52 | } 53 | 54 | ParseElement(arguments, nr_rows, nr_cols, nr_nzeros); 55 | in.close(); 56 | } 57 | 58 | // Returns false at EOF 59 | bool DoRead(ifstream &in, vector &arguments) 60 | { 61 | string buff; 62 | 63 | try { 64 | if (getline(in, buff).eof()) { 65 | return false; 66 | } 67 | } catch (ios_base::failure &e) { 68 | LOG_ERROR << "error reading from MMF file: " << (string) e.what(); 69 | exit(1); 70 | } 71 | 72 | buff = boost::trim_left_copy(buff); 73 | buff = boost::trim_right_copy(buff); 74 | boost::split(arguments, buff, boost::algorithm::is_any_of(" "), 75 | boost::algorithm::token_compress_on); 76 | 77 | return true; 78 | } 79 | 80 | } // end of namespace io 81 | } // end of namespace sparsex 82 | -------------------------------------------------------------------------------- /src/internals/Node.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2009-2012, Vasileios Karakasis 5 | * Copyright (C) 2010-2012, Theodoros Gkountouvas 6 | * All rights reserved. 7 | * 8 | * This file is distributed under the BSD License. See LICENSE.txt for details. 9 | */ 10 | 11 | /** 12 | * \file Node.cpp 13 | * \brief Node class 14 | * 15 | * \author Computing Systems Laboratory (CSLab), NTUA 16 | * \date 2011–2014 17 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 18 | * for details. 19 | */ 20 | 21 | #include 22 | 23 | using namespace std; 24 | 25 | namespace sparsex { 26 | namespace csx { 27 | 28 | Node::Node(uint32_t depth) 29 | : depth_(depth) 30 | { 31 | type_path_ = new Encoding::Type[depth_]; 32 | type_ignore_ = new Encoding::Type[Encoding::Max]; 33 | for (Encoding::Type t = Encoding::None; t < Encoding::Max; t++) 34 | type_ignore_[t] = Encoding::None; 35 | } 36 | 37 | void Node::PrintNode() 38 | { 39 | for (uint32_t i = 0; i < depth_; ++i) { 40 | if (i != 0) 41 | cout << ","; 42 | 43 | cout << type_path_[i]; 44 | } 45 | 46 | cout << endl; 47 | for (uint32_t i = 0; i < depth_; ++i) { 48 | Encoding::Type temp_type = type_path_[i]; 49 | set::iterator it = deltas_path_[temp_type].begin(); 50 | 51 | if (i != 0) 52 | cout << ","; 53 | 54 | cout << "{"; 55 | for (uint32_t i = 1; 56 | i < static_cast(deltas_path_[temp_type].size()); 57 | ++i) { 58 | cout << *it << ","; 59 | ++it; 60 | } 61 | 62 | cout << *it << "}"; 63 | } 64 | 65 | cout << endl; 66 | } 67 | 68 | void Node::Ignore(Encoding::Type type) 69 | { 70 | uint32_t i = 0; 71 | while (type_ignore_[i] != Encoding::None) { 72 | assert(type_ignore_[i] != type && "type already ignored"); 73 | ++i; 74 | } 75 | 76 | type_ignore_[i] = type; 77 | } 78 | 79 | Node Node::MakeChild(Encoding::Type type, set deltas) 80 | { 81 | Node new_node = Node(depth_ + 1); 82 | 83 | for (Encoding::Type t = Encoding::None; t < Encoding::Max; ++t) 84 | new_node.type_ignore_[t] = type_ignore_[t]; 85 | 86 | for (size_t i = 0; i < depth_; ++i) { 87 | Encoding::Type temp_type = type_path_[i]; 88 | new_node.type_path_[i] = temp_type; 89 | new_node.deltas_path_[temp_type] = deltas_path_[temp_type]; 90 | } 91 | 92 | new_node.type_path_[depth_] = type; 93 | new_node.deltas_path_[type] = deltas; 94 | return new_node; 95 | } 96 | 97 | } // end of namespace csx 98 | } // end of namespace sparsex 99 | -------------------------------------------------------------------------------- /src/internals/Statistics.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file Statistics.cpp 11 | * \brief SparseX statistics collection framework 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | 21 | using namespace std; 22 | 23 | namespace sparsex { 24 | namespace csx { 25 | 26 | typedef typename StatsCollection::InstStats InstStats; 27 | 28 | void SplitBlockData(size_t fixed_dim, size_t var_dim, size_t max_var_dim, 29 | const StatsData &data, InstStats &stats) 30 | { 31 | size_t nr_chunks = var_dim / max_var_dim; 32 | size_t rem_dim = var_dim % max_var_dim; 33 | size_t max_block_size = max_var_dim * fixed_dim; 34 | size_t nr_max_blocks = nr_chunks*data.GetPatterns(); 35 | size_t rem_nr_nzeros = data.GetEncoded() - nr_max_blocks*max_block_size; 36 | stats[max_var_dim] += StatsData(nr_max_blocks*max_block_size, 37 | nr_max_blocks, 0); 38 | if (rem_dim >= 2) 39 | // ignore one-dimensional remainders 40 | stats[rem_dim] += StatsData(rem_nr_nzeros, data.GetPatterns(), 0); 41 | } 42 | 43 | void EraseDims(InstStats &stats, vector &dims) 44 | { 45 | for (size_t i = 0; i < dims.size(); ++i) 46 | stats.erase(dims[i]); 47 | dims.clear(); 48 | } 49 | 50 | 51 | bool BlockSplitter::Manipulate(Encoding::Type type, InstStats &stats) 52 | { 53 | Encoding e(type); 54 | if (!e.IsBlock()) 55 | return false; 56 | 57 | size_t fixed_dim = e.GetBlockAlignment(); 58 | size_t max_block_dim = max_patt_size_ / fixed_dim; 59 | int ret = 0; 60 | vector dims_to_erase; 61 | 62 | // Split stats to max_patt_size_ chunks 63 | InstStats::reverse_iterator i = stats.rbegin(); 64 | for (; i != stats.rend() && i->first*fixed_dim > max_patt_size_; ++i) { 65 | SplitBlockData(fixed_dim, i->first, max_block_dim, i->second, stats); 66 | dims_to_erase.push_back(i->first); 67 | ++ret; 68 | } 69 | 70 | EraseDims(stats, dims_to_erase); 71 | InstStats::reverse_iterator j = stats.rbegin(); 72 | for (i = stats.rbegin(); i != stats.rend(); ++i) { 73 | if ((i->second.GetEncoded() / (double) nr_nzeros_) < min_coverage_) 74 | continue; 75 | for (; j != stats.rend() && j->first >= i->first && 76 | j->second.GetEncoded() / (double) nr_nzeros_ < min_coverage_; 77 | ++j) { 78 | SplitBlockData(fixed_dim, j->first, i->first, j->second, stats); 79 | dims_to_erase.push_back(j->first); 80 | ++ret; 81 | } 82 | 83 | } 84 | 85 | EraseDims(stats, dims_to_erase); 86 | return ret; 87 | } 88 | 89 | } // end of namespace csx 90 | } // end of namespace sparsex 91 | -------------------------------------------------------------------------------- /src/internals/TemplateText.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file TemplateText.cpp 11 | * \brief Class for manipulating template texts 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | 21 | using namespace boost; 22 | using namespace std; 23 | 24 | namespace sparsex { 25 | namespace jit { 26 | 27 | TemplateText::TemplateText(string text) 28 | : template_text_(text), placeholder_pattern_("\\$\\{(\\w+)\\}") 29 | { 30 | ReplacePlaceholders(); 31 | } 32 | 33 | void TemplateText::SetTemplate(string text) 34 | { 35 | template_text_ = text; 36 | ReplacePlaceholders(); 37 | } 38 | 39 | 40 | string TemplateText::Substitute(const std::map &values) 41 | { 42 | std::map::const_iterator iter = values.begin(); 43 | std::map::const_iterator iter_end = 44 | values.end(); 45 | 46 | for (; iter != iter_end; ++iter) { 47 | if (placeholders_.count(iter->first)) 48 | placeholders_[iter->first] = iter->second; 49 | else 50 | LOG_ERROR << "key '" << iter->first << "' not found\n"; 51 | } 52 | 53 | return DoSubstitute(); 54 | } 55 | 56 | void TemplateText::ReplacePlaceholders() 57 | { 58 | placeholders_.clear(); 59 | 60 | // Scan template text for keys 61 | string::const_iterator s_start = template_text_.begin(); 62 | string::const_iterator s_end = template_text_.end(); 63 | match_results match; 64 | 65 | while (regex_search(s_start, s_end, match, placeholder_pattern_)) { 66 | string key(match[1].first, match[1].second); 67 | placeholders_[key] = string(""); 68 | s_start = match[0].second; 69 | } 70 | } 71 | 72 | string TemplateText::DoSubstitute() 73 | { 74 | string ret; 75 | regex_replace(back_inserter(ret), 76 | template_text_.begin(), template_text_.end(), 77 | placeholder_pattern_, TextReplacer(this), match_default); 78 | return ret; 79 | } 80 | 81 | } // end of namespace jit 82 | } // end of namespace sparsex 83 | -------------------------------------------------------------------------------- /src/internals/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2013, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2010-2012, Vasileios Karakasis 4 | * Copyright (C) 2012-2013, Athena Elafrou 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file Timer.cpp 12 | * \brief Timing utilities 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | 26 | namespace sparsex { 27 | namespace timing { 28 | 29 | void Timer::Start() 30 | { 31 | if (gettimeofday(×tamp_, NULL) < 0) { 32 | cerr << "timer error: gettimeofday()" << endl; 33 | exit(1); 34 | } 35 | } 36 | 37 | void Timer::Pause() 38 | { 39 | struct timeval t_stop; 40 | struct timeval t_interval; 41 | 42 | if (gettimeofday(&t_stop, NULL) < 0) { 43 | cerr << "timer error: gettimeofday()" << endl; 44 | exit(1); 45 | } 46 | 47 | timersub(&t_stop, ×tamp_, &t_interval); 48 | timeradd(&elapsed_time_, &t_interval, &elapsed_time_); 49 | } 50 | 51 | void Timer::Stop() 52 | { 53 | Timer::Pause(); 54 | Timer::Clear(); 55 | } 56 | 57 | void Timer::Clear() 58 | { 59 | timerclear(&elapsed_time_); 60 | timerclear(×tamp_); 61 | } 62 | 63 | double Timer::ElapsedTime() 64 | { 65 | return (elapsed_time_.tv_sec + 66 | elapsed_time_.tv_usec / (double) 1000000); //USEC_PER_SEC 67 | } 68 | 69 | } // end of namespace timing 70 | } // end of namespace sparsex 71 | -------------------------------------------------------------------------------- /src/internals/TimerCollection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013 Athena Elafrou 4 | * Copyright (C) 2014 Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file TimerCollection.cpp 12 | * \brief A collection of arbitrary timers 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | 22 | namespace sparsex { 23 | namespace timing { 24 | 25 | void TimerCollection::PrintAllTimers(ostream &os) const 26 | { 27 | boost::unordered_map::const_iterator it; 28 | 29 | for (it = timers_.cbegin(); it != timers_.cend(); ++it) { 30 | Timer tm = it->second; 31 | double t = tm.ElapsedTime(); 32 | os << tm.GetDescription() << ": " << t << "\n"; 33 | } 34 | } 35 | 36 | } // end of namespace timing 37 | } // end of namespace sparsex 38 | -------------------------------------------------------------------------------- /src/internals/futex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2016, Computing Systems Laboratory (CSLab), NTUA 3 | * Copyright (C) 2016, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file futex.h 11 | * \brief Linux futex wrapper 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2016 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | void futex_wait(int *addr, int val) 26 | { 27 | int err = syscall(SYS_futex, addr, FUTEX_WAIT, val, NULL); 28 | if (err < 0 && errno == ENOSYS) 29 | syscall(SYS_futex, addr, FUTEX_WAIT, val, NULL); 30 | } 31 | 32 | void futex_wake(int *addr, int count) 33 | { 34 | // Wakes at most count processes waiting on the addr 35 | int err = syscall(SYS_futex, addr, FUTEX_WAKE, count); 36 | if (err < 0 && errno == ENOSYS) 37 | syscall(SYS_futex, addr, FUTEX_WAKE, count); 38 | } 39 | -------------------------------------------------------------------------------- /src/internals/logger/OutputPolicy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013-2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /** 10 | * \file OutputPolicy.cpp 11 | * \brief Output policies for logging 12 | * 13 | * \author Computing Systems Laboratory (CSLab), NTUA 14 | * \date 2011–2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | 21 | namespace sparsex { 22 | namespace logging { 23 | 24 | void StdPolicy::operator()(const buffer_type &buffer) 25 | { 26 | if (pthread_mutex_lock(&write_mutex_) != 0) { 27 | cerr << "[LOGGER]: failed to lock shared variable." 28 | << endl; 29 | exit(1); 30 | } 31 | 32 | cerr << buffer.str(); 33 | 34 | if (pthread_mutex_unlock(&write_mutex_) != 0) { 35 | cerr << "[LOGGER]: failed to unlock shared variable." 36 | << endl; 37 | exit(1); 38 | } 39 | } 40 | 41 | void FilePolicy::Init(const char *log_file) 42 | { 43 | try { 44 | os_.open(log_file, ios_base::binary); 45 | if (!os_.is_open()) { 46 | throw ios_base::failure(""); 47 | } 48 | } catch (ios_base::failure &e) { 49 | throw ios_base::failure("[LOGGER]: failed to open output stream, " 50 | "so logging will not take place."); 51 | } 52 | } 53 | 54 | void FilePolicy::operator()(const buffer_type &buffer) 55 | { 56 | if (pthread_mutex_lock(&write_mutex_) != 0) { 57 | cerr << "[LOGGER]: failed to lock shared variable." 58 | << endl; 59 | exit(1); 60 | } 61 | 62 | os_ << buffer.str(); 63 | 64 | if (pthread_mutex_unlock(&write_mutex_) != 0) { 65 | cerr << "[LOGGER]: failed to unlock shared variable." 66 | << endl; 67 | exit(1); 68 | } 69 | } 70 | 71 | } // end of namespace logging 72 | } // end of namespace sparsex 73 | -------------------------------------------------------------------------------- /src/templates/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- CSX multiplication templates 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All rights reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | 13 | templatesdir = $(datarootdir)/sparsex/templates 14 | dist_templates_DATA = \ 15 | block_col_one_tmpl.c \ 16 | block_col_sym_tmpl.c \ 17 | block_col_tmpl.c \ 18 | block_row_one_tmpl.c \ 19 | block_row_sym_tmpl.c \ 20 | block_row_tmpl.c \ 21 | csx_spmv_tmpl.c \ 22 | csx_sym_spmv_tmpl.c \ 23 | delta_sym_tmpl.c \ 24 | delta_tmpl.c \ 25 | diag_sym_tmpl.c \ 26 | diag_tmpl.c \ 27 | horiz_sym_tmpl.c \ 28 | horiz_tmpl.c \ 29 | rdiag_sym_tmpl.c \ 30 | rdiag_tmpl.c \ 31 | vert_sym_tmpl.c \ 32 | vert_tmpl.c 33 | -------------------------------------------------------------------------------- /src/templates/block_col_one_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file block_col_one_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | block_col_${r}x${c}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t **x_curr, spx_value_t **y_curr, 23 | spx_value_t scale_f) 24 | { 25 | register spx_value_t xr = **x_curr; 26 | register spx_value_t *y_curr_ = *y_curr; 27 | 28 | for (spx_index_t yi = 0; yi < ${r}; yi++) { 29 | y_curr_[yi] += xr * (**values) * scale_f; 30 | (*values)++; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/templates/block_col_sym_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2014, Vasileios Karakasis 4 | * Copyright (C) 2011, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file block_col_sym_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | block_col_${r}x${c}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t *x, spx_value_t *y, spx_value_t *cur, 23 | spx_index_t *x_indx, spx_index_t *y_indx, 24 | spx_value_t scale_f) 25 | { 26 | register spx_value_t values_ = **values; 27 | register spx_index_t x_indx_ = *x_indx; 28 | register spx_value_t *x_ = x + x_indx_; 29 | register spx_value_t *ry_ = cur + x_indx_; 30 | register spx_index_t y_indx_ = *y_indx; 31 | register spx_value_t *y_ = y + y_indx_; 32 | register spx_value_t *rx_ = x + y_indx_; 33 | register spx_value_t curr_y_ = 0; 34 | register spx_value_t curr_rx_ = *rx_; 35 | spx_index_t i, j; 36 | 37 | for (i = 0; i < ${r}; i++) { 38 | for (j = 0; j < ${c}; j++) { 39 | curr_y_ += x_[j] * values_; 40 | ry_[j] += curr_rx_ * values_ * scale_f; 41 | (*values)++; 42 | values_ = **values; 43 | } 44 | 45 | (*y_) += curr_y_ * scale_f; 46 | y_++; 47 | rx_++; 48 | curr_y_ = 0; 49 | curr_rx_ = *rx_; 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /src/templates/block_col_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file block_col_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | block_col_${r}x${c}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t **x_curr, spx_value_t **y_curr, 23 | spx_value_t scale_f) 24 | { 25 | register spx_value_t *y_curr_ = *y_curr; 26 | register spx_value_t *x_curr_ = *x_curr; 27 | 28 | for (spx_index_t i = 0; i < ${r}; i++) { 29 | register spx_value_t yr = 0; 30 | 31 | for (spx_index_t j = 0; j < ${c}; j++) { 32 | yr += x_curr_[j] * (**values); 33 | (*values)++; 34 | } 35 | 36 | y_curr_[i] += yr * scale_f; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /src/templates/block_row_one_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file block_row_one_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | block_row_${r}x${c}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t **x_curr, spx_value_t **y_curr, 23 | spx_value_t scale_f) 24 | { 25 | register spx_value_t yr = 0; 26 | register spx_value_t *x_curr_ = *x_curr; 27 | 28 | for (spx_index_t i = 0; i < ${c}; i++) { 29 | yr += x_curr_[i] * (**values); 30 | (*values)++; 31 | } 32 | 33 | return yr * scale_f; 34 | } 35 | -------------------------------------------------------------------------------- /src/templates/block_row_sym_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2014, Vasileios Karakasis 4 | * Copyright (C) 2011, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file block_row_sym_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | block_row_${r}x${c}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t *x, spx_value_t *y, spx_value_t *cur, 23 | spx_index_t *x_indx, spx_index_t *y_indx, 24 | spx_value_t scale_f) 25 | { 26 | register spx_value_t values_ = **values; 27 | register spx_index_t x_indx_ = *x_indx; 28 | register spx_value_t *x_ = x + x_indx_; 29 | register spx_value_t *ry_ = cur + x_indx_; 30 | register spx_index_t y_indx_ = *y_indx; 31 | register spx_value_t *y_ = y + y_indx_; 32 | register spx_value_t *rx_ = x + y_indx_; 33 | register spx_value_t curr_x_ = *x_; 34 | register spx_value_t curr_ry_ = 0; 35 | 36 | for (spx_index_t i = 0; i < ${c}; i++) { 37 | for (spx_index_t j = 0; j < ${r}; j++) { 38 | y_[j] += curr_x_ * values_ * scale_f; 39 | curr_ry_ += rx_[j] * values_; 40 | (*values)++; 41 | values_ = **values; 42 | } 43 | 44 | (*ry_) += curr_ry_ * scale_f; 45 | x_++; 46 | ry_++; 47 | curr_x_ = *x_; 48 | curr_ry_ = 0; 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /src/templates/block_row_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file block_row_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | block_row_${r}x${c}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t **x_curr, spx_value_t **y_curr, 23 | spx_value_t scale_f) 24 | { 25 | register spx_value_t *y_curr_ = *y_curr; 26 | register spx_value_t *x_curr_ = *x_curr; 27 | 28 | for (spx_index_t i = 0; i < ${c}; i++) { 29 | register spx_value_t xr = x_curr_[i]; 30 | for (spx_index_t j = 0; j < ${r}; j++) { 31 | y_curr_[j] += xr * (**values) * scale_f; 32 | (*values)++; 33 | } 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /src/templates/csx_spmv_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file csx_spmv_tmpl.c 12 | * \brief The CSX multiplication template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define CSX_SPMV_FN_MAX CTL_PATTERNS_MAX 30 | 31 | #define ALIGN(buf, a) (void *) (((unsigned long) (buf) + (a-1)) & ~(a-1)) 32 | 33 | #pragma GCC diagnostic push 34 | #pragma GCC diagnostic ignored "-Wunused-function" 35 | // the following function will be unused when only delta8 units 36 | // are present 37 | static void align_ptr(uint8_t **ctl, int align) 38 | { 39 | *ctl = ALIGN(*ctl, align); 40 | } 41 | #pragma GCC diagnostic pop 42 | 43 | #if SPX_DEBUG 44 | static void ctl_print(uint8_t *ctl, spx_index_t start, spx_index_t end, 45 | const char *descr) 46 | { 47 | for (spx_index_t i = start; i < end; i++) { 48 | printf("%s[%ld]: %p = %d\n", descr, i, &ctl[i], ctl[i]); 49 | fflush(stdout); 50 | } 51 | } 52 | 53 | static void deref(void *ptr) 54 | { 55 | volatile unsigned long val = *((unsigned long *) ptr); 56 | val++; 57 | } 58 | #endif 59 | 60 | typedef spx_value_t (csx_spmv_fn_t)(uint8_t **ctl, uint8_t size, 61 | spx_value_t **values, 62 | spx_value_t **x, spx_value_t **y); 63 | 64 | ${spmv_func_definitions} 65 | 66 | void spm_csx_multiply(void *spm, vector_t *in, vector_t *out, 67 | spx_value_t scale_f, vector_t *local_out /* unused */) 68 | { 69 | csx_matrix_t *csx = (csx_matrix_t *) spm; 70 | spx_value_t *x = in->elements; 71 | spx_value_t *y = out->elements; 72 | spx_value_t *v = csx->values; 73 | spx_value_t *x_curr = x; 74 | spx_value_t *y_curr = y + csx->row_start; 75 | register spx_value_t yr = 0; 76 | uint8_t *ctl = csx->ctl; 77 | uint8_t *ctl_end = ctl + csx->ctl_size; 78 | uint8_t size, flags; 79 | uint8_t patt_id; 80 | 81 | /* uint8_t *ctl_start = ctl; */ 82 | /* ctl_print(ctl, 0, csx->ctl_size, "ctl"); */ 83 | do { 84 | flags = *ctl++; 85 | size = *ctl++; 86 | if (test_bit(&flags, CTL_NR_BIT)) { 87 | *y_curr += yr; 88 | yr = 0; 89 | ${new_row_hook} 90 | x_curr = x; 91 | } 92 | 93 | ${next_x} 94 | patt_id = flags & CTL_PATTERN_MASK; 95 | ${body_hook} 96 | /* printf("ctl moved at %zd bytes\n", ctl - ctl_start); */ 97 | /* fflush(stdout); */ 98 | } while (ctl < ctl_end); 99 | 100 | *y_curr += yr; 101 | } 102 | -------------------------------------------------------------------------------- /src/templates/csx_sym_spmv_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2014, Vasileios Karakasis 4 | * Copyright (C) 2011, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file csx_sym_spmv_tmpl.c 12 | * \brief The CSX-sym multiplication template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define CSX_SPMV_FN_MAX CTL_PATTERNS_MAX 30 | 31 | #define ALIGN(buf,a) (void *) (((unsigned long) (buf) + (a-1)) & ~(a-1)) 32 | 33 | #pragma GCC diagnostic push 34 | #pragma GCC diagnostic ignored "-Wunused-function" 35 | // the following function will be unused when only delta8 units 36 | // are present 37 | static void align_ptr(uint8_t **ctl, int align) 38 | { 39 | *ctl = ALIGN(*ctl, align); 40 | } 41 | #pragma GCC diagnostic pop 42 | 43 | #if SPX_DEBUG 44 | static void ctl_print(uint8_t *ctl, spx_index_t start, spx_index_t end, 45 | const char *descr) 46 | { 47 | for (spx_index_t i = start; i < end; i++) 48 | printf("%s: ctl[%ld] = %d\n", descr, i, ctl[i]); 49 | } 50 | 51 | static void deref(void *ptr) 52 | { 53 | volatile unsigned long val = *((unsigned long *) ptr); 54 | val++; 55 | } 56 | #endif 57 | 58 | ${spmv_func_definitions} 59 | 60 | void spm_csx_sym_multiply(void *spm, vector_t *in, vector_t *out, 61 | spx_value_t scale_f, vector_t *local_out) 62 | { 63 | csx_sym_matrix_t *csx_sym = (csx_sym_matrix_t *) spm; 64 | csx_matrix_t *csx = csx_sym->lower_matrix; 65 | spx_value_t *x = in->elements; 66 | spx_value_t *y = out->elements; 67 | spx_value_t *tmp = local_out->elements; 68 | spx_value_t *v = csx->values; 69 | spx_value_t *dv = csx_sym->dvalues; 70 | spx_index_t x_indx = 0; 71 | spx_index_t y_indx = csx->row_start; 72 | spx_index_t y_end = csx->row_start + csx->nrows; 73 | spx_index_t i; 74 | register spx_value_t yr = 0; 75 | uint8_t *ctl = csx->ctl; 76 | uint8_t *ctl_end = ctl + csx->ctl_size; 77 | uint8_t flags, size, patt_id; 78 | spx_value_t *cur = tmp; 79 | 80 | do { 81 | flags = *ctl++; 82 | size = *ctl++; 83 | if (test_bit(&flags, CTL_NR_BIT)) { 84 | y[y_indx] += yr; 85 | ${new_row_hook} 86 | yr = 0; 87 | x_indx = 0; 88 | // Switch Reduction Phase 89 | cur = tmp; 90 | } 91 | 92 | ${next_x} 93 | // Switch Reduction Phase 94 | if (cur != y && x_indx >= csx->row_start) 95 | cur = y; 96 | patt_id = flags & CTL_PATTERN_MASK; 97 | ${body_hook} 98 | } while (ctl < ctl_end); 99 | 100 | y[y_indx] += yr; 101 | 102 | for (i = y_indx; i < y_end; i++) { 103 | y[i] += x[i] * (*dv) * scale_f; 104 | dv++; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/templates/delta_sym_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2014, Vasileios Karakasis 4 | * Copyright (C) 2011, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file delta_sym_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | delta${bits}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t *x, spx_value_t *y, spx_value_t *cur, 23 | spx_index_t *x_indx, spx_index_t *y_indx, 24 | spx_value_t scale_f) 25 | { 26 | register spx_value_t yr = 0; 27 | register spx_value_t values_ = **values; 28 | register spx_index_t x_indx_ = *x_indx; 29 | register spx_value_t *x_ = x + x_indx_; 30 | register spx_value_t *ry_ = cur + x_indx_; 31 | register spx_index_t y_indx_ = *y_indx; 32 | register spx_value_t rx_ = x[y_indx_]; 33 | register spx_index_t jmp; 34 | 35 | ${align_ctl} 36 | yr += (*x_) * values_; 37 | (*ry_) += rx_ * values_ * scale_f; 38 | (*values)++; 39 | for (uint8_t i = 1; i < size; i++) { 40 | jmp = u${bits}_get(ctl); 41 | x_ += jmp; 42 | ry_ += jmp; 43 | (*x_indx) += jmp; 44 | values_ = **values; 45 | yr += (*x_) * values_; 46 | (*ry_) += rx_ * values_ * scale_f; 47 | (*values)++; 48 | } 49 | 50 | return yr * scale_f; 51 | } 52 | -------------------------------------------------------------------------------- /src/templates/delta_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file delta_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | delta${bits}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t **x_curr, spx_value_t **y_curr, 23 | spx_value_t scale_f) 24 | { 25 | register spx_value_t yr; 26 | 27 | ${align_ctl} 28 | yr = (**x_curr) * (**values); 29 | (*values)++; 30 | for (uint8_t i = 1; i < size; i++) { 31 | *x_curr += u${bits}_get(ctl); 32 | yr += (**x_curr) * (**values); 33 | (*values)++; 34 | } 35 | 36 | return yr * scale_f; 37 | } 38 | -------------------------------------------------------------------------------- /src/templates/diag_sym_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2014, Vasileios Karakasis 4 | * Copyright (C) 2011, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file diag_sym_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | diag${delta}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t *x, spx_value_t *y, spx_value_t *cur, 23 | spx_index_t *x_indx, spx_index_t *y_indx, 24 | spx_value_t scale_f) 25 | { 26 | register spx_value_t values_ = **values; 27 | register spx_index_t x_indx_ = *x_indx; 28 | register spx_value_t *x_ = x + x_indx_; 29 | register spx_value_t *ry_ = cur + x_indx_; 30 | register spx_index_t y_indx_ = *y_indx; 31 | register spx_value_t *y_ = y + y_indx_; 32 | register spx_value_t *rx_ = x + y_indx_; 33 | register spx_index_t i_end = ${delta} * size; 34 | 35 | for (spx_index_t i = 0; i < i_end; i += ${delta}) { 36 | y_[i] += x_[i] * values_ * scale_f; 37 | ry_[i] += rx_[i] * values_ * scale_f; 38 | (*values)++; 39 | values_ = **values; 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /src/templates/diag_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file diag_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | diag${delta}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t **x_curr, spx_value_t **y_curr, 23 | spx_value_t scale_f) 24 | { 25 | register spx_value_t *y_curr_ = *y_curr; 26 | register spx_value_t *x_curr_ = *x_curr; 27 | register spx_index_t i_end = ${delta}*size; 28 | 29 | for (spx_index_t i = 0; i < i_end; i += ${delta}) { 30 | y_curr_[i] += x_curr_[i] * (**values) * scale_f; 31 | (*values)++; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /src/templates/horiz_sym_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2014, Vasileios Karakasis 4 | * Copyright (C) 2011, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file horiz_sym_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | horiz${delta}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t *x, spx_value_t *y, spx_value_t *cur, 23 | spx_index_t *x_indx, spx_index_t *y_indx, 24 | spx_value_t scale_f) 25 | { 26 | register spx_value_t yr = 0; 27 | register spx_value_t values_ = **values; 28 | register spx_index_t x_indx_ = *x_indx; 29 | register spx_value_t *x_ = x + x_indx_; 30 | register spx_value_t *ry_ = cur + x_indx_; 31 | register spx_index_t y_indx_ = *y_indx; 32 | register spx_value_t rx_ = x[y_indx_]; 33 | register spx_index_t i_end = ${delta}*size; 34 | 35 | for (spx_index_t i = 0; i < i_end; i += ${delta}) { 36 | yr += x_[i] * values_; 37 | ry_[i] += rx_ * values_ * scale_f; 38 | (*values)++; 39 | values_ = **values; 40 | } 41 | 42 | // Move x_indx to the last element of the pattern 43 | (*x_indx) += i_end - ${delta}; 44 | return yr * scale_f; 45 | } 46 | -------------------------------------------------------------------------------- /src/templates/horiz_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file horiz_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | horiz${delta}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t **x_curr, spx_value_t **y_curr, 23 | spx_value_t scale_f) 24 | { 25 | register spx_value_t yr = 0; 26 | register spx_value_t *x_curr_ = *x_curr; 27 | register spx_index_t i_end = ${delta}*size; 28 | 29 | for (spx_index_t i = 0; i < i_end; i += ${delta}) { 30 | yr += x_curr_[i] * (**values); 31 | (*values)++; 32 | } 33 | 34 | // Move x_curr to the last element of the pattern 35 | (*x_curr) += (i_end - ${delta}); 36 | return yr * scale_f; 37 | } 38 | -------------------------------------------------------------------------------- /src/templates/rdiag_sym_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2014, Vasileios Karakasis 4 | * Copyright (C) 2011, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file rdiag_sym_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | rdiag${delta}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t *x, spx_value_t *y, spx_value_t *cur, 23 | spx_index_t *x_indx, spx_index_t *y_indx, 24 | spx_value_t scale_f) 25 | { 26 | register spx_value_t values_ = **values; 27 | register spx_index_t i_end = ${delta} * size; 28 | register spx_index_t x_indx_ = *x_indx; 29 | register spx_value_t *x_ = x + x_indx_ - i_end; 30 | register spx_value_t *ry_ = cur + x_indx_ - i_end; 31 | register spx_index_t y_indx_ = *y_indx; 32 | register spx_value_t *y_ = y + y_indx_; 33 | register spx_value_t *rx_ = x + y_indx_; 34 | spx_index_t i, j; 35 | 36 | for (i = 0, j = i_end; i < i_end; i += ${delta}, j -= ${delta}) { 37 | y_[i] += x_[j] * values_ * scale_f; 38 | ry_[j] += rx_[i] * values_ * scale_f; 39 | (*values)++; 40 | values_ = **values; 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/templates/rdiag_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file rdiag_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | rdiag${delta}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t **x_curr, spx_value_t **y_curr, 23 | spx_value_t scale_f) 24 | { 25 | register spx_value_t *x_curr_ = *x_curr; 26 | register spx_value_t *y_curr_ = *y_curr; 27 | register spx_index_t i_end = ${delta}*size; 28 | 29 | for (spx_index_t i = 0; i < i_end; i += ${delta}) { 30 | y_curr_[i] += (*x_curr_) * (**values) * scale_f; 31 | x_curr_ -= ${delta}; 32 | (*values)++; 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /src/templates/vert_sym_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2014, Vasileios Karakasis 4 | * Copyright (C) 2011, Theodoros Gkountouvas 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file vert_sym_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | vert${delta}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t *x, spx_value_t *y, spx_value_t *cur, 23 | spx_index_t *x_indx, spx_index_t *y_indx, 24 | spx_value_t scale_f) 25 | { 26 | register spx_value_t values_ = **values; 27 | register spx_index_t x_indx_ = *x_indx; 28 | register spx_value_t x_ = x[x_indx_]; 29 | register spx_value_t ry_ = 0; 30 | register spx_index_t y_indx_ = *y_indx; 31 | register spx_value_t *y_ = y + y_indx_; 32 | register spx_value_t *rx_ = x + y_indx_; 33 | register spx_index_t i_end = ${delta} * size; 34 | 35 | for (spx_index_t i = 0; i < i_end; i += ${delta}) { 36 | y_[i] += x_ * values_ * scale_f; 37 | ry_ += rx_[i] * values_; 38 | (*values)++; 39 | values_ = **values; 40 | } 41 | cur[x_indx_] += ry_ * scale_f; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/templates/vert_tmpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2009-2011, Kornilios Kourtis 4 | * Copyright (C) 2011-2014, Vasileios Karakasis 5 | * All rights reserved. 6 | * 7 | * This file is distributed under the BSD License. See LICENSE.txt for details. 8 | */ 9 | 10 | /** 11 | * \file vert_tmpl.c 12 | * \brief Template for runtime code generation. 13 | * 14 | * \author Computing Systems Laboratory (CSLab), NTUA 15 | * \date 2011–2014 16 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 17 | * for details. 18 | */ 19 | 20 | static inline spx_value_t 21 | vert${delta}_case(uint8_t **ctl, uint8_t size, spx_value_t **values, 22 | spx_value_t **x_curr, spx_value_t **y_curr, 23 | spx_value_t scale_f) 24 | { 25 | register spx_value_t xr = **x_curr; 26 | register spx_index_t yi_end = ${delta}*size; 27 | register spx_value_t *y_curr_ = *y_curr; 28 | 29 | for (spx_index_t yi = 0; yi < yi_end; yi += ${delta}) { 30 | y_curr_[yi] += xr * (**values) * scale_f; 31 | (*values)++; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- Top-level Makefile.am for test suite 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All righrs reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | SUBDIRS = matrices src 13 | -------------------------------------------------------------------------------- /test/matrices/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- Test matrices 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All righrs reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | 13 | dist_noinst_DATA = \ 14 | demopatt.mtx.sorted \ 15 | demopatt.mtx.unsorted \ 16 | symmetric.mtx.sorted \ 17 | symmetric-very-sparse.mtx.sorted -------------------------------------------------------------------------------- /test/matrices/demopatt.mtx.sorted: -------------------------------------------------------------------------------- 1 | 10 10 38 2 | 1 1 1 3 | 1 2 2 4 | 1 3 3 5 | 1 4 4 6 | 1 9 5 7 | 2 8 6 8 | 3 1 7 9 | 3 2 8 10 | 3 7 9 11 | 3 10 10 12 | 4 1 11 13 | 4 2 12 14 | 4 4 13 15 | 4 6 14 16 | 4 10 15 17 | 5 1 16 18 | 5 2 17 19 | 5 10 18 20 | 6 1 19 21 | 6 2 20 22 | 6 6 21 23 | 6 10 22 24 | 7 3 23 25 | 7 4 24 26 | 8 3 25 27 | 8 4 26 28 | 8 5 26.1 29 | 8 6 26.2 30 | 8 8 27 31 | 9 3 28 32 | 9 4 29 33 | 9 5 29.1 34 | 9 6 29.2 35 | 10 3 30 36 | 10 4 31 37 | 10 5 31.1 38 | 10 6 31.2 39 | 10 10 32 40 | -------------------------------------------------------------------------------- /test/matrices/demopatt.mtx.unsorted: -------------------------------------------------------------------------------- 1 | 10 10 38 2 | 1 9 5 3 | 1 1 1 4 | 1 3 3 5 | 1 2 2 6 | 1 4 4 7 | 2 8 6 8 | 3 1 7 9 | 3 10 10 10 | 3 2 8 11 | 3 7 9 12 | 4 4 13 13 | 4 1 11 14 | 4 2 12 15 | 4 6 14 16 | 4 10 15 17 | 5 1 16 18 | 5 2 17 19 | 5 10 18 20 | 6 1 19 21 | 6 2 20 22 | 6 6 21 23 | 6 10 22 24 | 7 3 23 25 | 7 4 24 26 | 8 3 25 27 | 8 4 26 28 | 8 6 26.2 29 | 8 8 27 30 | 8 5 26.1 31 | 9 3 28 32 | 9 4 29 33 | 9 5 29.1 34 | 9 6 29.2 35 | 10 3 30 36 | 10 6 31.2 37 | 10 4 31 38 | 10 5 31.1 39 | 10 10 32 40 | -------------------------------------------------------------------------------- /test/matrices/symmetric-very-sparse.mtx.sorted: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate real symmetric 1-base row 2 | % 3 | % non-zeros off diagonal less than the number of rows 4 | % 5 | 8 8 12 6 | 1 1 2.7 7 | 2 1 0.5 8 | 2 2 5.6 9 | 3 1 3.1 10 | 3 3 9.4 11 | 4 4 0.7 12 | 5 5 2.4 13 | 6 2 9.8 14 | 6 6 7.8 15 | 7 7 9.8 16 | 8 5 3.3 17 | 8 8 4.1 18 | -------------------------------------------------------------------------------- /test/matrices/symmetric.mtx.sorted: -------------------------------------------------------------------------------- 1 | %%MatrixMarket matrix coordinate real symmetric 1-base row 2 | 8 8 21 3 | 1 1 2.7 4 | 2 1 0.5 5 | 2 2 5.6 6 | 3 1 3.1 7 | 3 2 6.6 8 | 3 3 9.4 9 | 4 3 5.4 10 | 4 4 0.7 11 | 5 1 1.2 12 | 5 5 2.4 13 | 6 2 9.8 14 | 6 3 4.1 15 | 6 4 7.2 16 | 6 5 1.9 17 | 6 6 7.8 18 | 7 5 4.6 19 | 7 6 4.7 20 | 7 7 9.8 21 | 8 5 3.3 22 | 8 6 3.4 23 | 8 8 4.1 24 | -------------------------------------------------------------------------------- /test/matrices/test.mtx.sorted: -------------------------------------------------------------------------------- 1 | 81 81 90 2 | 1 1 2 3 | 1 10 5 4 | 1 11 2 5 | 1 12 3 6 | 1 13 4 7 | 1 14 5 8 | 1 21 7 9 | 1 41 6 10 | 1 61 5 11 | 1 81 3 12 | 2 2 2 13 | 3 3 2 14 | 4 4 2 15 | 5 5 2 16 | 6 6 2 17 | 7 7 2 18 | 8 8 2 19 | 9 9 2 20 | 10 10 2 21 | 11 11 2 22 | 12 12 2 23 | 13 13 2 24 | 14 14 2 25 | 15 15 2 26 | 16 16 2 27 | 17 17 2 28 | 18 18 2 29 | 19 19 2 30 | 20 20 2 31 | 21 21 2 32 | 22 22 2 33 | 23 23 2 34 | 24 24 2 35 | 25 25 2 36 | 26 26 2 37 | 27 27 2 38 | 28 28 2 39 | 29 29 2 40 | 30 30 2 41 | 31 31 2 42 | 32 32 2 43 | 33 33 2 44 | 34 34 2 45 | 35 35 2 46 | 36 36 2 47 | 37 37 2 48 | 38 38 2 49 | 39 39 2 50 | 40 40 2 51 | 41 41 2 52 | 42 42 2 53 | 43 43 2 54 | 44 44 2 55 | 45 45 2 56 | 46 46 2 57 | 47 47 2 58 | 48 48 2 59 | 49 49 2 60 | 50 50 2 61 | 51 51 2 62 | 52 52 2 63 | 53 53 2 64 | 54 54 2 65 | 55 55 2 66 | 56 56 2 67 | 57 57 2 68 | 58 58 2 69 | 59 59 2 70 | 60 60 2 71 | 61 61 2 72 | 62 62 2 73 | 63 63 2 74 | 64 64 2 75 | 65 65 2 76 | 66 66 2 77 | 67 67 2 78 | 68 68 2 79 | 69 69 2 80 | 70 70 2 81 | 71 71 2 82 | 72 72 2 83 | 73 73 2 84 | 74 74 2 85 | 75 75 2 86 | 76 76 2 87 | 77 77 2 88 | 78 78 2 89 | 79 79 2 90 | 80 80 2 91 | 81 81 2 92 | -------------------------------------------------------------------------------- /test/matrices/test3.mtx.sorted: -------------------------------------------------------------------------------- 1 | 81 81 93 2 | 1 1 2 3 | 1 10 5 4 | 1 11 2 5 | 1 12 3 6 | 1 13 4 7 | 1 14 5 8 | 1 21 7 9 | 1 31 7 10 | 1 41 6 11 | 1 51 6 12 | 1 61 5 13 | 1 71 5 14 | 1 81 3 15 | 2 2 2 16 | 3 3 2 17 | 4 4 2 18 | 5 5 2 19 | 6 6 2 20 | 7 7 2 21 | 8 8 2 22 | 9 9 2 23 | 10 10 2 24 | 11 11 2 25 | 12 12 2 26 | 13 13 2 27 | 14 14 2 28 | 15 15 2 29 | 16 16 2 30 | 17 17 2 31 | 18 18 2 32 | 19 19 2 33 | 20 20 2 34 | 21 21 2 35 | 22 22 2 36 | 23 23 2 37 | 24 24 2 38 | 25 25 2 39 | 26 26 2 40 | 27 27 2 41 | 28 28 2 42 | 29 29 2 43 | 30 30 2 44 | 31 31 2 45 | 32 32 2 46 | 33 33 2 47 | 34 34 2 48 | 35 35 2 49 | 36 36 2 50 | 37 37 2 51 | 38 38 2 52 | 39 39 2 53 | 40 40 2 54 | 41 41 2 55 | 42 42 2 56 | 43 43 2 57 | 44 44 2 58 | 45 45 2 59 | 46 46 2 60 | 47 47 2 61 | 48 48 2 62 | 49 49 2 63 | 50 50 2 64 | 51 51 2 65 | 52 52 2 66 | 53 53 2 67 | 54 54 2 68 | 55 55 2 69 | 56 56 2 70 | 57 57 2 71 | 58 58 2 72 | 59 59 2 73 | 60 60 2 74 | 61 61 2 75 | 62 62 2 76 | 63 63 2 77 | 64 64 2 78 | 65 65 2 79 | 66 66 2 80 | 67 67 2 81 | 68 68 2 82 | 69 69 2 83 | 70 70 2 84 | 71 71 2 85 | 72 72 2 86 | 73 73 2 87 | 74 74 2 88 | 75 75 2 89 | 76 76 2 90 | 77 77 2 91 | 78 78 2 92 | 79 79 2 93 | 80 80 2 94 | 81 81 2 95 | -------------------------------------------------------------------------------- /test/src/BinaryTest_p1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /* 10 | * \file BinaryTest_p1.cpp 11 | * \brief Simple program for testing matrix caching feature 12 | * 13 | * \author Athena Elafrou 14 | * \date 2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace std; 31 | using namespace sparsex::csx; 32 | using namespace sparsex::io; 33 | using namespace sparsex::utilities; 34 | 35 | static const char *program_name; 36 | 37 | int main(int argc, char **argv) 38 | { 39 | EnableInfoConsole(); 40 | RtConfig &config = RtConfig::GetInstance(); 41 | config.LoadFromEnv(); 42 | config.CheckProperties(); 43 | RtCtx &rt_context = RtCtx::GetInstance(); 44 | rt_context.SetRtCtx(config); 45 | 46 | program_name = argv[0]; 47 | char c; 48 | while ((c = getopt(argc, argv, "bsh")) != -1) { 49 | switch (c) { 50 | case 'h': 51 | // PrintUsage(std::cerr); 52 | exit(0); 53 | default: 54 | // PrintUsage(std::cerr); 55 | exit(1); 56 | } 57 | } 58 | 59 | int remargc = argc - optind; // remaining arguments 60 | if (remargc < 1) { 61 | // PrintUsage(std::cerr); 62 | exit(1); 63 | } 64 | argv = &argv[optind]; 65 | 66 | sparsex::timing::Timer timer; 67 | SparseMatrix > matrix(argv[0]); 68 | spm_mt_t *spm_mt = 0; 69 | timer.Start(); 70 | spm_mt = matrix.CreateCsx(); 71 | timer.Pause(); 72 | double pt_time = timer.ElapsedTime(); 73 | 74 | timer.Clear(); 75 | timer.Start(); 76 | matrix.Save("csx_file"); 77 | timer.Pause(); 78 | double dump_time = timer.ElapsedTime(); 79 | 80 | cout << "PART1 m: " << basename(argv[0]) 81 | << " pt: " << pt_time 82 | << " dump: " << dump_time 83 | << endl; 84 | 85 | PutSpmMt(spm_mt); 86 | 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /test/src/BinaryTest_p2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2014, Athena Elafrou 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /* 10 | * \file BinaryTest_p2.cpp 11 | * \brief Simple program for testing matrix caching feature 12 | * 13 | * \author Athena Elafrou 14 | * \date 2014 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | using namespace sparsex::csx; 30 | using namespace sparsex::io; 31 | using namespace sparsex::utilities; 32 | 33 | static const char *program_name; 34 | 35 | int main(int argc, char **argv) 36 | { 37 | program_name = argv[0]; 38 | spm_mt_t *spm_mt = 0; 39 | sparsex::timing::Timer timer; 40 | 41 | cout << "=== BEGIN BENCHMARK ===" << endl; 42 | cout << "Reconstructing CSX from binary file..." << endl; 43 | timer.Start(); 44 | spm_mt = RestoreCsx("csx_file", NULL); 45 | timer.Pause(); 46 | double rebuild_time = timer.ElapsedTime(); 47 | 48 | cout << "Assigning new values to all matrix entries..." << endl; 49 | MMF mmf(argv[1]); 50 | int count = mmf.GetNrNonzeros()/spm_mt->nr_threads; 51 | MMF::iterator iter = mmf.begin(); 52 | MMF::iterator iter_end = mmf.end(); 53 | timer.Clear(); 54 | timer.Start(); 55 | for (int i = 0; iter != iter_end, i < count; ++iter, i++) { 56 | SetValueCsx(spm_mt, (*iter).GetRow(), 57 | (*iter).GetCol(), 0.42); 58 | } 59 | 60 | timer.Pause(); 61 | double assign_time = timer.ElapsedTime(); 62 | cout << "=== END BENCHMARK ===" << endl; 63 | 64 | PutSpmMt(spm_mt); 65 | 66 | cout << "PART2 m: " << basename(argv[1]) 67 | << " rebuild: " << rebuild_time 68 | << " assign: " << assign_time 69 | << endl; 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /test/src/CsxCheck.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2012, Vasileios Karakasis 4 | * Copyright (C) 2011-2012, Theodoros Gkountouvas 5 | * Copyright (C) 2013-2014, Athena Elafrou 6 | * All rights reserved. 7 | * 8 | * This file is distributed under the BSD License. See LICENSE.txt for details. 9 | */ 10 | 11 | /* 12 | * \file CsxCheck.cpp 13 | * \brief Checking utilities 14 | * 15 | * \author Vasileios Karakasis 16 | * \author Theodoros Gkountouvas 17 | * \author Athena Elafrou 18 | * \date 2011–2014 19 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 20 | * for details. 21 | */ 22 | 23 | #include 24 | #include "CsxCheck.hpp" 25 | 26 | using namespace sparsex::io; 27 | 28 | static void csr_spmv(CSR *spm, vector_t *in, 29 | vector_t *out) 30 | { 31 | spx_value_t *x = in->elements; 32 | spx_value_t *y = out->elements; 33 | const spx_value_t *values = spm->values_; 34 | const spx_uindex_t *row_ptr = spm->rowptr_; 35 | const spx_uindex_t *col_ind = spm->colind_; 36 | const spx_uindex_t row_start = 0; 37 | const spx_uindex_t row_end = spm->GetNrRows(); 38 | register spx_value_t yr; 39 | spx_uindex_t i,j; 40 | 41 | for (i = row_start; i < row_end; i++) { 42 | yr = (spx_value_t) 0; 43 | for (j = row_ptr[i]; j < row_ptr[i+1]; j++) 44 | yr += (values[j] * x[col_ind[j]]); 45 | 46 | y[i] = yr; 47 | } 48 | } 49 | 50 | void check_result(vector_t *result, double alpha, vector_t *x, 51 | char *matrix_file) 52 | { 53 | CheckResult(result, alpha, x, matrix_file); 54 | } 55 | -------------------------------------------------------------------------------- /test/src/CsxCheck.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2014, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2011-2012, Vasileios Karakasis 4 | * Copyright (C) 2011-2012, Theodoros Gkountouvas 5 | * Copyright (C) 2013-2014, Athena Elafrou 6 | * All rights reserved. 7 | * 8 | * This file is distributed under the BSD License. See LICENSE.txt for details. 9 | */ 10 | 11 | /* 12 | * \file CsxCheck.hpp 13 | * \brief Checking utilities 14 | * 15 | * \author Vasileios Karakasis 16 | * \author Theodoros Gkountouvas 17 | * \author Athena Elafrou 18 | * \date 2011–2014 19 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 20 | * for details. 21 | */ 22 | 23 | #ifndef SPARSEX_TEST_CHECK_HPP 24 | #define SPARSEX_TEST_CHECK_HPP 25 | 26 | #include 27 | 28 | #ifdef __cplusplus 29 | // C++ only 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | using namespace std; 37 | using namespace sparsex::io; 38 | 39 | /** 40 | * Read an MMF file and create the corresponding CSR format. 41 | */ 42 | template 43 | void MMFtoCSR(const char *filename, IndexType **rowptr, IndexType **colind, 44 | ValueType **values, size_t *nrows, size_t *ncols, size_t *nnz) 45 | { 46 | MMF mmf(filename); 47 | *nrows = mmf.GetNrRows(); 48 | *ncols = mmf.GetNrCols(); 49 | *nnz = mmf.GetNrNonzeros(); 50 | *values = new ValueType[mmf.GetNrNonzeros()]; 51 | *colind = new IndexType[mmf.GetNrNonzeros()]; 52 | *rowptr = new IndexType[mmf.GetNrRows() + 1]; 53 | 54 | typename MMF::iterator iter = mmf.begin(); 55 | typename MMF::iterator iter_end = mmf.end(); 56 | IndexType row_i = 0, val_i = 0, row_prev = 0; 57 | IndexType row, col; 58 | ValueType val; 59 | 60 | (*rowptr)[row_i++] = val_i; 61 | for (;iter != iter_end; ++iter) { 62 | row = (*iter).GetRow() - 1; 63 | col = (*iter).GetCol() - 1; 64 | val = (*iter).GetValue(); 65 | assert(row >= row_prev); 66 | if (row != row_prev) { 67 | for (IndexType i = 0; i < row - row_prev; i++) { 68 | (*rowptr)[row_i++] = val_i; 69 | } 70 | row_prev = row; 71 | } 72 | (*values)[val_i] = val; 73 | (*colind)[val_i] = col; 74 | val_i++; 75 | } 76 | 77 | (*rowptr)[row_i++] = val_i; 78 | } 79 | 80 | /** 81 | * Check the CSX SpMV result against the baseline single-thread CSR 82 | * implementation. 83 | */ 84 | template 85 | void CheckResult(vector_t *result, ValueType alpha, vector_t *x, 86 | char *matrix_file) 87 | { 88 | CSR *csr = new CSR; 89 | MMFtoCSR(matrix_file, &csr->rowptr_, &csr->colind_, 90 | &csr->values_, &csr->nr_rows_, 91 | &csr->nr_cols_, &csr->nr_nzeros_); 92 | 93 | cout << "Checking... " << flush; 94 | vector_t *y_csr = VecCreate(csr->nr_rows_); 95 | csr_spmv(csr, x, y_csr); 96 | VecScale(y_csr, y_csr, alpha); 97 | if (VecCompare(y_csr, result) < 0) 98 | exit(1); 99 | cout << "Check Passed" << endl; 100 | 101 | // Cleanup 102 | delete[] csr->rowptr_; 103 | delete[] csr->colind_; 104 | delete[] csr->values_; 105 | delete csr; 106 | } 107 | 108 | #endif 109 | 110 | SPX_BEGIN_C_DECLS__ 111 | void check_result(vector_t *result, double alpha, vector_t *x, 112 | char *matrix_file); 113 | SPX_END_C_DECLS__ 114 | 115 | #endif // SPARSEX_TEST_CHECK_HPP 116 | -------------------------------------------------------------------------------- /test/src/DynamicArrayTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /* 10 | * \file DynamicArray.cpp 11 | * \brief Test dynamic array implementation 12 | * 13 | * \author Vasileios Karakasis 14 | * \date 2013 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | using namespace sparsex::timing; 27 | using namespace sparsex::utilities; 28 | 29 | class MyClass 30 | { 31 | public: 32 | MyClass(size_t a, size_t b) 33 | : a_(a), b_(b) 34 | {} 35 | 36 | MyClass() 37 | : a_(0), b_(0) 38 | {} 39 | 40 | ~MyClass() {} 41 | private: 42 | size_t a_, b_; 43 | }; 44 | 45 | int main(void) 46 | { 47 | const size_t array_size = 50000000; 48 | // const size_t array_size = 100; 49 | const size_t capacity = 10; 50 | DynamicArray > dynarray(capacity); 51 | vector vec(capacity); 52 | Timer timer; 53 | 54 | timer.Start(); 55 | for (size_t i = 0; i < array_size; ++i) { 56 | //MyClass my(i, i+1); 57 | dynarray.Append(i); 58 | } 59 | 60 | timer.Pause(); 61 | cout << "C++ dynamic array impl.: " << timer.ElapsedTime() << " s\n"; 62 | timer.Stop(); 63 | 64 | timer.Start(); 65 | for (size_t i = 0; i < array_size; ++i) { 66 | //MyClass my(i, i+1); 67 | vec.push_back(i); 68 | } 69 | 70 | timer.Pause(); 71 | cout << "Vector impl.: " << timer.ElapsedTime() << " s\n"; 72 | timer.Stop(); 73 | 74 | StdAllocator &alloc = StdAllocator::GetInstance(); 75 | int *array = new (alloc) int[array_size]; 76 | 77 | timer.Start(); 78 | for (size_t i = 0; i < array_size; ++i) 79 | array[i] = i; 80 | 81 | timer.Pause(); 82 | cout << "Normal array: " << timer.ElapsedTime() << " s\n"; 83 | alloc.Destroy(array, array_size); 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /test/src/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am -- SparseX tests 3 | # 4 | # Copyright (C) 2014, Computing Systems Laboratory (CSLab), NTUA 5 | # Copyright (C) 2014, Vasileios Karakasis 6 | # All righrs reserved. 7 | # 8 | # This file is distributed under the BSD License. See LICENSE.txt for details. 9 | # 10 | 11 | AM_DEFAULT_VERBOSITY = 0 12 | ACLOCAL_AMFLAGS = -I m4check 13 | 14 | AM_CPPFLAGS = \ 15 | -I$(top_builddir)/include \ 16 | -I$(top_srcdir)/include \ 17 | $(AX_CPPFLAGS) 18 | 19 | AM_CFLAGS = $(AX_CFLAGS) 20 | AM_CXXFLAGS = $(AX_CXXFLAGS) 21 | AM_LDFLAGS = \ 22 | -L$(top_builddir)/src/internals/.libs \ 23 | $(AX_LDFLAGS) 24 | 25 | SPARSEXIMPL_LDADD = \ 26 | $(top_builddir)/src/internals/.libs/libsparseximpl.la 27 | 28 | check_PROGRAMS = test_sparsex test_element test_dynarray test_timer \ 29 | test_binary_p1 test_binary_p2 30 | 31 | noinst_HEADERS = CsxCheck.hpp 32 | 33 | test_sparsex_SOURCES = \ 34 | CsxCheck.cpp \ 35 | sparsex_test.c 36 | test_sparsex_LDFLAGS = -rpath $(LLVM_LIBDIR) 37 | test_sparsex_LDADD = \ 38 | $(top_builddir)/src/api/.libs/libsparsex.la 39 | 40 | test_element_SOURCES = ElementTest.cpp 41 | test_element_LDFLAGS = -rpath $(LLVM_LIBDIR) 42 | test_element_LDADD = $(SPARSEXIMPL_LDADD) 43 | 44 | test_dynarray_SOURCES = DynamicArrayTest.cpp 45 | test_dynarray_LDFLAGS = -rpath $(LLVM_LIBDIR) 46 | test_dynarray_LDADD = $(SPARSEXIMPL_LDADD) 47 | 48 | test_timer_SOURCES = TimerTest.cpp 49 | test_timer_LDFLAGS = -rpath $(LLVM_LIBDIR) 50 | test_timer_LDADD = $(SPARSEXIMPL_LDADD) 51 | 52 | test_binary_p1_SOURCES = BinaryTest_p1.cpp 53 | test_binary_p1_LDFLAGS = -rpath $(LLVM_LIBDIR) 54 | test_binary_p1_LDADD = $(SPARSEXIMPL_LDADD) 55 | 56 | test_binary_p2_SOURCES = BinaryTest_p2.cpp 57 | test_binary_p2_LDFLAGS = -rpath $(LLVM_LIBDIR) 58 | test_binary_p2_LDADD = $(SPARSEXIMPL_LDADD) 59 | -------------------------------------------------------------------------------- /test/src/TimerTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013, Computing Systems Laboratory (CSLab), NTUA. 3 | * Copyright (C) 2013, Vasileios Karakasis 4 | * All rights reserved. 5 | * 6 | * This file is distributed under the BSD License. See LICENSE.txt for details. 7 | */ 8 | 9 | /* 10 | * \file TimerTest.cpp 11 | * \brief Test timer 12 | * 13 | * \author Vasileios Karakasis 14 | * \date 2013 15 | * \copyright This file is distributed under the BSD License. See LICENSE.txt 16 | * for details. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | using namespace sparsex::timing; 26 | 27 | int main() 28 | { 29 | Timer timer; 30 | 31 | cout << "sleeping for 1 second and reporting:\n"; 32 | timer.Start(); 33 | sleep(1); 34 | timer.Pause(); 35 | cout << "timed %lf secs\n", timer.ElapsedTime(); 36 | 37 | timer.Clear(); 38 | cout << "sleeping 2 times for 1 second and reporting:\n"; 39 | timer.Start(); 40 | sleep(1); 41 | timer.Pause(); 42 | 43 | sleep(1); 44 | 45 | timer.Start(); 46 | sleep(1); 47 | timer.Pause(); 48 | cout << "timed %lf secs\n", timer.ElapsedTime(); 49 | 50 | return 0; 51 | } 52 | --------------------------------------------------------------------------------