summaryrefslogtreecommitdiffstats
path: root/include/ixion/compute_engine.hpp
blob: 6e5bbd7670672d93f3c28a95c58398e8b03dbb45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef INCLUDED_IXION_COMPUTE_ENGINE_HPP
#define INCLUDED_IXION_COMPUTE_ENGINE_HPP

#include "env.hpp"
#include "module.hpp"

#include <memory>
#include <string>

namespace ixion { namespace draft {

enum class array_type { unknown, float32, float64, uint32 };

struct array
{
    union
    {
        float* float32;
        double* float64;
        uint32_t* uint32;
        void* data;
    };

    array_type type = array_type::unknown;
    std::size_t size = 0u;
};

/**
 * Default compute engine class that uses CPU for all its computations.
 *
 * <p>This class also serves as the fallback for its child classes in case
 * they don't support the function being requested or the function doesn't
 * meet the criteria that it requires.</p>
 *
 * <p>Each function of this class should not modify the state of the class
 * instance.</p>
 */
class IXION_DLLPUBLIC compute_engine
{
    struct impl;
    std::unique_ptr<impl> mp_impl;

public:
    /**
     * Create a compute engine instance.
     *
     * @param name name of the compute engine, or an empty name for the default
     *             one.
     *
     * @return compute engine instance associted with the specified name. Note
     *         that if no compute engine is registered with the specified
     *         name, the default one is created.
     */
    static std::shared_ptr<compute_engine> create(std::string_view name = std::string_view());

    /**
     * Add a new compute engine class.
     *
     * @param hdl handler for the dynamically-loaded module in which the
     *            compute engine being registered resides.
     * @param name name of the compute engine.
     * @param func_create function that creates a new instance of this compute
     *                    engine class.
     * @param func_destroy function that destroyes the instance of this
     *                     compute engine class.
     */
    static void add_class(
        void* hdl, std::string_view name, create_compute_engine_t func_create, destroy_compute_engine_t func_destroy);

    compute_engine();
    virtual ~compute_engine();

    virtual std::string_view get_name() const;

    virtual void compute_fibonacci(array& io);
};

}}

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */