Commit 8d5d49f6 authored by Cianciosa, Mark's avatar Cianciosa, Mark
Browse files

Fix some errors in the comments. Add the ability to define output nodes and...

Fix some errors in the comments. Add the ability to define output nodes and change the setters type from a map to an vector of pairs.
parent 8466d10a
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -81,15 +81,15 @@ int main(int argc, const char * argv[]) {
            ky->set(backend::base_cast<cpu> (0.0));
            kz->set(backend::base_cast<cpu> (0.0));
            
            //auto eq = equilibrium::make_slab_density<cpu> ();
            auto eq = equilibrium::make_no_magnetic_field<cpu> ();
            auto eq = equilibrium::make_slab_density<cpu> ();
            //auto eq = equilibrium::make_no_magnetic_field<cpu> ();

            //solver::split_simplextic<dispersion::bohm_gross<cpu>>
            solver::rk4<dispersion::bohm_gross<cpu>>
            //solver::rk4<dispersion::bohm_gross<cpu>>
            //solver::rk4<dispersion::simple<cpu>>
            //solver::rk4<dispersion::ordinary_wave<cpu>>
            //solver::rk4<dispersion::extra_ordinary_wave<cpu>>
            //solver::rk4<dispersion::cold_plasma<cpu>>
            solver::rk4<dispersion::cold_plasma<cpu>>
                solve(omega, kx, ky, kz, x, y, z, t, 60.0/num_times, eq);
            solve.init(kx);
            solve.compile(num_times, num_rays);
+5 −5
Original line number Diff line number Diff line
@@ -375,7 +375,7 @@ namespace graph {
        return add<LN, RN> (l, r);
    }

///  Convience type alias for shared add nodes.
///  Convenience type alias for shared add nodes.
    template<typename LN, typename RN>
    using shared_add = std::shared_ptr<add_node<LN, RN>>;

@@ -680,7 +680,7 @@ namespace graph {
        return subtract<LN, RN> (l, r);
    }

///  Convience type alias for shared subtract nodes.
///  Convenience type alias for shared subtract nodes.
    template<typename LN, typename RN>
    using shared_subtract = std::shared_ptr<subtract_node<LN, RN>>;

@@ -1056,7 +1056,7 @@ namespace graph {
        return multiply<LN, RN> (l, r);
    }

///  Convience type alias for shared multiply nodes.
///  Convenience type alias for shared multiply nodes.
    template<typename LN, typename RN>
    using shared_multiply = std::shared_ptr<multiply_node<LN, RN>>;

@@ -1361,7 +1361,7 @@ namespace graph {
        return divide<LN, RN> (l, r);
    }

///  Convience type alias for shared divide nodes.
///  Convenience type alias for shared divide nodes.
    template<typename LN, typename RN>
    using shared_divide = std::shared_ptr<divide_node<LN, RN>>;

@@ -1618,7 +1618,7 @@ namespace graph {
        return std::make_shared<fma_node<LN, MN, RN>> (l, m, r)->reduce();
    }

///  Convience type alias for shared add nodes.
///  Convenience type alias for shared add nodes.
    template<typename LN, typename MN, typename RN>
    using shared_fma = std::shared_ptr<fma_node<LN, MN, RN>>;

+5 −5
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ namespace equilibrium {
                           graph::shared_leaf<BACKEND> z) = 0;
    };

///  Convience type alias for unique equilibria.
///  Convenience type alias for unique equilibria.
    template<typename BACKEND>
    using unique_equilibrium = std::unique_ptr<equilibrium<BACKEND>>;

@@ -232,7 +232,7 @@ namespace equilibrium {
        }
    };

///  Convience type alias for unique equilibria.
///  Convenience type alias for unique equilibria.
    template<typename BACKEND>
    std::unique_ptr<equilibrium<BACKEND>> make_no_magnetic_field() {
        return std::make_unique<no_magnetic_field<BACKEND>> ();
@@ -328,7 +328,7 @@ namespace equilibrium {
        }
    };

///  Convience type alias for unique equilibria.
///  Convenience type alias for unique equilibria.
    template<typename BACKEND>
    std::unique_ptr<equilibrium<BACKEND>> make_slab() {
        return std::make_unique<slab<BACKEND>> ();
@@ -426,7 +426,7 @@ namespace equilibrium {
        }
    };

///  Convience type alias for unique equilibria.
///  Convenience type alias for unique equilibria.
    template<typename BACKEND>
    std::unique_ptr<equilibrium<BACKEND>> make_slab_density() {
        return std::make_unique<slab_density<BACKEND>> ();
@@ -522,7 +522,7 @@ namespace equilibrium {
        }
    };

///  Convience type alias for unique equilibria.
///  Convenience type alias for unique equilibria.
    template<typename BACKEND>
    std::unique_ptr<equilibrium<BACKEND>> make_guassian_density() {
        return std::make_unique<guassian_density<BACKEND>> ();
+38 −5
Original line number Diff line number Diff line
@@ -47,22 +47,29 @@ namespace jit {
///
///  @param[in] name    Name to call the kernel.
///  @param[in] inputs  Input variables of the kernel.
///  @param[in] outputs Output nodes of the graph to compute.
///  @param[in] setters Map outputs back to input values.
//------------------------------------------------------------------------------
        kernel(const std::string name,
               graph::input_nodes<BACKEND> inputs,
               graph::output_nodes<BACKEND> outputs,
               graph::map_nodes<BACKEND> setters) {
            const size_t test_size = inputs[0]->size();
            
            create_preamble(name);
            add_kernel_argument(to_string('v', inputs[0].get()), 0);
            
            add_kernel_argument(to_string('v', inputs[0].get()), 0);
            for (size_t i = 1, ie = inputs.size(); i < ie; i++) {
                assert(test_size == inputs[i]->size() &&
                       "Kernel input variables all need to be the same size.");
                add_kernel_argument(to_string('v', inputs[i].get()), i);
            }
            
            for (size_t i = 0, ie = outputs.size(); i < ie; i++) {
                add_kernel_argument(to_string('o', outputs[i].get()),
                                    i + inputs.size());
            }

            add_argument_index(test_size);
            
            for (graph::shared_variable<BACKEND> &input : inputs) {
@@ -72,12 +79,20 @@ namespace jit {
            for (auto &[out, in] : setters) {
                out->compile(source_buffer, registers);
            }
            for (auto &out : outputs) {
                out->compile(source_buffer, registers);
            }

            for (auto &[out, in] : setters) {
                graph::shared_leaf<BACKEND> a = out->compile(source_buffer, registers);
                store_variable(in.get(), registers[a.get()]);
            }
            
            for (auto &out : outputs) {
                graph::shared_leaf<BACKEND> a = out->compile(source_buffer, registers);
                store_node(out.get(), registers[a.get()]);
            }

            source_buffer << "}" << std::endl;
        }

@@ -190,6 +205,18 @@ namespace jit {
                          << "[index] = " << result << ";" << std::endl;
        }

//------------------------------------------------------------------------------
///  @brief Store the final buffer.
///
///  @param[in] pointer Pointer to the result node.
///  @param[in] result  Name of the result reguster.
//------------------------------------------------------------------------------
        void store_node(graph::leaf_node<BACKEND> *pointer,
                        const std::string result) {
            source_buffer << "    " << to_string('o',  pointer)
                          << "[index] = " << result << ";" << std::endl;
        }

//------------------------------------------------------------------------------
///  @brief Print the kernel source.
//------------------------------------------------------------------------------
@@ -200,15 +227,21 @@ namespace jit {
//------------------------------------------------------------------------------
///  @brief Compile the kernel.
///
///  @param[in] name      Name of the kernel for reference.
///  @param[in] inputs    Input variables of the kernel.
///  @param[in] outputs   Output nodes to calculate results of.
///  @param[in] num_steps Number of time steps.
///  @param[in] num_rays  Number of rays.
//------------------------------------------------------------------------------
        void compile(const std::string name,
                     graph::input_nodes<BACKEND> inputs,
                     graph::output_nodes<BACKEND> outputs,
                     const size_t num_steps,
                     const size_t num_rays) {
            GPU_CONTEXT context;
            context.create_pipeline(source_buffer.str(), name, inputs, num_rays,
                                    num_steps, 0);
            context.create_pipeline(source_buffer.str(), name,
                                    inputs, outputs,
                                    num_rays, num_steps, 0);
            
            const timeing::measure_diagnostic gpu_time("GPU Time");

+4 −4
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ namespace graph {
        return (std::make_shared<sqrt_node<N>> (x))->reduce();
    }

///  Convience type alias for shared sqrt nodes.
///  Convenience type alias for shared sqrt nodes.
    template<typename N>
    using shared_sqrt = std::shared_ptr<sqrt_node<N>>;

@@ -319,7 +319,7 @@ namespace graph {
        return (std::make_shared<exp_node<N>> (x))->reduce();
    }

///  Convience type alias for shared exp nodes.
///  Convenience type alias for shared exp nodes.
    template<typename N>
    using shared_exp = std::shared_ptr<exp_node<N>>;

@@ -455,7 +455,7 @@ namespace graph {
        return (std::make_shared<log_node<N>> (x))->reduce();
    }

///  Convience type alias for shared exp nodes.
///  Convenience type alias for shared exp nodes.
    template<typename N>
    using shared_log = std::shared_ptr<log_node<N>>;

@@ -667,7 +667,7 @@ namespace graph {
        return std::make_shared<pow_node<LN, RN>> (l, r)->reduce();
    }

///  Convience type alias for shared add nodes.
///  Convenience type alias for shared add nodes.
    template<typename LN, typename RN>
    using shared_pow = std::shared_ptr<pow_node<LN, RN>>;

Loading