spla
Loading...
Searching...
No Matches
registry.hpp
Go to the documentation of this file.
1/**********************************************************************************/
2/* This file is part of spla project */
3/* https://github.com/SparseLinearAlgebra/spla */
4/**********************************************************************************/
5/* MIT License */
6/* */
7/* Copyright (c) 2023 SparseLinearAlgebra */
8/* */
9/* Permission is hereby granted, free of charge, to any person obtaining a copy */
10/* of this software and associated documentation files (the "Software"), to deal */
11/* in the Software without restriction, including without limitation the rights */
12/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13/* copies of the Software, and to permit persons to whom the Software is */
14/* furnished to do so, subject to the following conditions: */
15/* */
16/* The above copyright notice and this permission notice shall be included in all */
17/* copies or substantial portions of the Software. */
18/* */
19/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25/* SOFTWARE. */
26/**********************************************************************************/
27
28#ifndef SPLA_REGISTRY_HPP
29#define SPLA_REGISTRY_HPP
30
31#include <spla/config.hpp>
32#include <spla/schedule.hpp>
33
34#include <robin_hood.hpp>
35
36#include <string>
37
38namespace spla {
39
40#define CPU_SUFFIX "__cpu"
41#define GPU_CL_SUFFIX "__cl"
42#define OP_KEY(op) "_" + (op)->get_key()
43#define TYPE_KEY(type) "_" + (type)->get_code()
44#define MAKE_KEY_0(name, type) std::string(name) + TYPE_KEY(type)
45#define MAKE_KEY_1(name, op) std::string(name) + OP_KEY(op)
46#define MAKE_KEY_2(name, op1, op2) std::string(name) + OP_KEY(op1) + OP_KEY(op2)
47#define MAKE_KEY_3(name, op1, op2, op3) std::string(name) + OP_KEY(op1) + OP_KEY(op2) + OP_KEY(op3)
48#define MAKE_KEY_CPU_0(name, type) MAKE_KEY_0(name, type) + CPU_SUFFIX
49#define MAKE_KEY_CPU_1(name, op) MAKE_KEY_1(name, op) + CPU_SUFFIX
50#define MAKE_KEY_CPU_2(name, op1, op2) MAKE_KEY_2(name, op1, op2) + CPU_SUFFIX
51#define MAKE_KEY_CPU_3(name, op1, op2, op3) MAKE_KEY_3(name, op1, op2, op3) + CPU_SUFFIX
52#define MAKE_KEY_CL_0(name, type) MAKE_KEY_0(name, type) + GPU_CL_SUFFIX
53#define MAKE_KEY_CL_1(name, op) MAKE_KEY_1(name, op) + GPU_CL_SUFFIX
54#define MAKE_KEY_CL_2(name, op1, op2) MAKE_KEY_2(name, op1, op2) + GPU_CL_SUFFIX
55#define MAKE_KEY_CL_3(name, op1, op2, op3) MAKE_KEY_3(name, op1, op2, op3) + GPU_CL_SUFFIX
56
67 public:
68 virtual ~RegistryAlgo() = default;
69 virtual std::string get_name() = 0;
70 virtual std::string get_description() = 0;
71 virtual Status execute(const struct DispatchContext& ctx) = 0;
72 };
73
78 class Registry {
79 public:
80 virtual ~Registry() = default;
81 virtual void add(const std::string& key, std::shared_ptr<RegistryAlgo> algo);
82 virtual bool has(const std::string& key);
83 virtual std::shared_ptr<RegistryAlgo> find(const std::string& key);
84
85 private:
86 robin_hood::unordered_flat_map<std::string, std::shared_ptr<RegistryAlgo>> m_registry;
87 };
88
93}// namespace spla
94
95#endif//SPLA_REGISTRY_HPP
Status of library operation execution.
Algorithm suitable to process schedule task based on task string key.
Definition registry.hpp:66
virtual std::string get_name()=0
virtual Status execute(const struct DispatchContext &ctx)=0
virtual ~RegistryAlgo()=default
virtual std::string get_description()=0
Registry with key-algo mapping of stored algo implementations.
Definition registry.hpp:78
virtual bool has(const std::string &key)
Definition registry.cpp:36
virtual void add(const std::string &key, std::shared_ptr< RegistryAlgo > algo)
Definition registry.cpp:32
virtual ~Registry()=default
virtual std::shared_ptr< RegistryAlgo > find(const std::string &key)
Definition registry.cpp:40
Definition algorithm.hpp:37
Execution context of a single task.
Definition dispatcher.hpp:46