#ifndef STORM_SOLVER_TOPOLOGICALCUDAMINMAXLINEAREQUATIONSOLVER_H_ #define STORM_SOLVER_TOPOLOGICALCUDAMINMAXLINEAREQUATIONSOLVER_H_ #include "storm/solver/MinMaxLinearEquationSolver.h" #include "storm/storage/StronglyConnectedComponentDecomposition.h" #include "storm/storage/SparseMatrix.h" #include "storm/exceptions/NotImplementedException.h" #include "storm/exceptions/NotSupportedException.h" #include #include #include "storm-config.h" #ifdef STORM_HAVE_CUDA #include "cudaForStorm.h" #endif namespace storm { namespace solver { /*! * A class that uses SCC Decompositions to solve a min/max linear equation system. */ template class TopologicalCudaMinMaxLinearEquationSolver : public MinMaxLinearEquationSolver { public: TopologicalCudaMinMaxLinearEquationSolver(); /*! * Constructs a min-max linear equation solver with parameters being set according to the settings * object. * * @param A The matrix defining the coefficients of the linear equation system. */ TopologicalCudaMinMaxLinearEquationSolver(storm::storage::SparseMatrix const& A); virtual void setMatrix(storm::storage::SparseMatrix const& matrix) override; virtual void setMatrix(storm::storage::SparseMatrix&& matrix) override; virtual bool internalSolveEquations(Environment const& env, OptimizationDirection dir, std::vector& x, std::vector const& b) const override; private: storm::storage::SparseMatrix const* A; std::unique_ptr> localA; bool enableCuda; /*! * Given a topological sort of a SCC Decomposition, this will calculate the optimal grouping of SCCs with respect to the size of the GPU memory. */ std::vector> getOptimalGroupingFromTopologicalSccDecomposition(storm::storage::StronglyConnectedComponentDecomposition const& sccDecomposition, std::vector const& topologicalSort, storm::storage::SparseMatrix const& matrix) const; }; template bool __basicValueIteration_mvReduce_minimize(uint_fast64_t const, double const, bool const, std::vector const&, std::vector> const&, std::vector& x, std::vector const&, std::vector const&, size_t&) { // STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Unsupported template arguments."); } template <> inline bool __basicValueIteration_mvReduce_minimize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector const& matrixRowIndices, std::vector> const& columnIndicesAndValues, std::vector& x, std::vector const& b, std::vector const& nondeterministicChoiceIndices, size_t& iterationCount) { (void)maxIterationCount; (void)precision; (void)relativePrecisionCheck; (void)matrixRowIndices; (void)columnIndicesAndValues; (void)x; (void)b; (void)nondeterministicChoiceIndices; (void)iterationCount; #ifdef STORM_HAVE_CUDA return basicValueIteration_mvReduce_uint64_double_minimize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Storm is compiled without CUDA support."); #endif } template <> inline bool __basicValueIteration_mvReduce_minimize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector const& matrixRowIndices, std::vector> const& columnIndicesAndValues, std::vector& x, std::vector const& b, std::vector const& nondeterministicChoiceIndices, size_t& iterationCount) { (void)maxIterationCount; (void)precision; (void)relativePrecisionCheck; (void)matrixRowIndices; (void)columnIndicesAndValues; (void)x; (void)b; (void)nondeterministicChoiceIndices; (void)iterationCount; #ifdef STORM_HAVE_CUDA return basicValueIteration_mvReduce_uint64_float_minimize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Storm is compiled without CUDA support."); #endif } template bool __basicValueIteration_mvReduce_maximize(uint_fast64_t const, double const, bool const, std::vector const&, std::vector> const&, std::vector&, std::vector const&, std::vector const&, size_t&) { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Unsupported template arguments."); } template <> inline bool __basicValueIteration_mvReduce_maximize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector const& matrixRowIndices, std::vector> const& columnIndicesAndValues, std::vector& x, std::vector const& b, std::vector const& nondeterministicChoiceIndices, size_t& iterationCount) { (void)maxIterationCount; (void)precision; (void)relativePrecisionCheck; (void)matrixRowIndices; (void)columnIndicesAndValues; (void)x; (void)b; (void)nondeterministicChoiceIndices; (void)iterationCount; #ifdef STORM_HAVE_CUDA return basicValueIteration_mvReduce_uint64_double_maximize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Storm is compiled without CUDA support."); #endif } template <> inline bool __basicValueIteration_mvReduce_maximize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector const& matrixRowIndices, std::vector> const& columnIndicesAndValues, std::vector& x, std::vector const& b, std::vector const& nondeterministicChoiceIndices, size_t& iterationCount) { (void)maxIterationCount; (void)precision; (void)relativePrecisionCheck; (void)matrixRowIndices; (void)columnIndicesAndValues; (void)x; (void)b; (void)nondeterministicChoiceIndices; (void)iterationCount; #ifdef STORM_HAVE_CUDA return basicValueIteration_mvReduce_uint64_float_maximize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Storm is compiled without CUDA support."); #endif } template class TopologicalCudaMinMaxLinearEquationSolverFactory : public MinMaxLinearEquationSolverFactory { public: TopologicalCudaMinMaxLinearEquationSolverFactory(bool trackScheduler = false); protected: virtual std::unique_ptr> create(Environment const& env) const override; }; } // namespace solver } // namespace storm #endif /* STORM_SOLVER_TOPOLOGICALCUDAMINMAXLINEAREQUATIONSOLVER_H_ */