Skip to content

Commit

Permalink
Param (#205)
Browse files Browse the repository at this point in the history
* test first step

* typo

* changed template

* changed template

* debug

* debug

* added matrixParam to AddForcingTermsKernelDriver

* changed header

* debug

* debug

* debug

* test

* passing vector_matrix directly

* debug

* implemented simple class

* add std::vector

* debug

* ahhh

* passing 3 matrix data as a group

* deleted const

* debug

* debug

* debug

* debug

* debug

* added matrix data in a group for AddJacobianFunction

* debug

* store d_rate_constants in struct pointer

* using cudaMallocManaged

* using cudaMallocManaged

* using cudaMallocManaged

* device strcut

* get all pointers into struct for AddJacobian

* debug

* debug

* passed?

* passing struct of processSet to kernelDriver

* clean up

* removed header

* group processSet data members into struct

* minor fix

* minor fix

* get rid of micm from struct

* debug

* debug

* minor fix

* minor fix

* minor fix

* clean up

* debug

* test

* clean up

* clean up

* clean up

* clean up

* test

* test out for storing pointer to variable

* store reused device pointer to variable in kernel

* store reused device pointer to variable in kernel

* added struct for sparseMatrix

* added struct for sparseMatrix

* sparse matrix in struct
  • Loading branch information
qinatan committed Sep 5, 2023
1 parent d1b34a2 commit 12b01eb
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 190 deletions.
37 changes: 7 additions & 30 deletions include/micm/process/cuda_process_set.cuh
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
#pragma once
#include <micm/util/cuda_param.hpp>

namespace micm
{
namespace cuda
{
std::chrono::nanoseconds AddForcingTermsKernelDriver(
const double* rate_constants_data,
const double* state_variables_data,
double* forcing_data,
size_t n_grids,
size_t n_reactions,
size_t n_species,
const size_t* number_of_reactants,
const size_t* reactant_ids,
size_t reactant_ids_size,
const size_t* number_of_products,
const size_t* product_ids,
size_t product_ids_size,
const double* yields,
size_t yields_size);
std::chrono::nanoseconds AddForcingTermsKernelDriver(
CUDAMatrixParam& matrixParam,
CUDAProcessSetParam& processSet);

std::chrono::nanoseconds AddJacobianTermsKernelDriver(
const double* rate_constants,
const double* state_variables,
size_t n_grids,
size_t n_reactions,
size_t n_species,
double* jacobian,
size_t jacobian_size,
const size_t* number_of_reactants,
const size_t* reactant_ids,
size_t reactant_ids_size,
const size_t* number_of_products,
const double* yields,
size_t yields_size,
const size_t* jacobian_flat_ids,
size_t jacobian_flat_ids_size);
CUDAMatrixParam& matrixParam,
CUDASparseMatrixParam& sparseMatrix,
CUDAProcessSetParam& processSet);
} // namespace cuda
} // namespace micm
74 changes: 45 additions & 29 deletions include/micm/process/cuda_process_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <micm/process/process_set.hpp>
#include <micm/util/cuda_param.hpp>

#ifdef USE_CUDA
# include <micm/process/cuda_process_set.cuh>
Expand Down Expand Up @@ -51,21 +52,27 @@ namespace micm
const MatrixPolicy<double>& state_variables,
MatrixPolicy<double>& forcing) const
{
CUDAMatrixParam matrixParam;
matrixParam.rate_constants = rate_constants.AsVector().data();
matrixParam.state_variables = state_variables.AsVector().data();
matrixParam.forcing = forcing.AsVector().data();
matrixParam.n_grids = rate_constants.size();
matrixParam.n_reactions = rate_constants[0].size();
matrixParam.n_species = state_variables[0].size();

CUDAProcessSetParam processSet;
processSet.number_of_reactants = number_of_reactants_.data();
processSet.reactant_ids = reactant_ids_.data();
processSet.reactant_ids_size = reactant_ids_.size();
processSet.number_of_products = number_of_products_.data();
processSet.product_ids = product_ids_.data();
processSet.product_ids_size = product_ids_.size();
processSet.yields = yields_.data();
processSet.yields_size = yields_.size();

std::chrono::nanoseconds kernel_duration = micm::cuda::AddForcingTermsKernelDriver(
rate_constants.AsVector().data(),
state_variables.AsVector().data(),
forcing.AsVector().data(),
rate_constants.size(),
rate_constants[0].size(),
state_variables[0].size(),
number_of_reactants_.data(),
reactant_ids_.data(),
reactant_ids_.size(),
number_of_products_.data(),
product_ids_.data(),
product_ids_.size(),
yields_.data(),
yields_.size());
matrixParam,
processSet);
return kernel_duration; // time performance of kernel function
}
template<template<class> class MatrixPolicy, template<class> class SparseMatrixPolicy>
Expand All @@ -75,22 +82,31 @@ namespace micm
const MatrixPolicy<double>& state_variables,
SparseMatrixPolicy<double>& jacobian) const
{
CUDAMatrixParam matrixParam;
matrixParam.rate_constants = rate_constants.AsVector().data();
matrixParam.state_variables = state_variables.AsVector().data();
matrixParam.n_grids = rate_constants.size();
matrixParam.n_reactions = rate_constants[0].size();
matrixParam.n_species = state_variables[0].size();

CUDASparseMatrixParam sparseMatrix;
sparseMatrix.jacobian = jacobian.AsVector().data();
sparseMatrix.jacobian_size = jacobian.AsVector().size();

CUDAProcessSetParam processSet;
processSet.number_of_reactants = number_of_reactants_.data();
processSet.reactant_ids = reactant_ids_.data();
processSet.reactant_ids_size = reactant_ids_.size();
processSet.number_of_products = number_of_products_.data();
processSet.yields = yields_.data();
processSet.yields_size = yields_.size();
processSet.jacobian_flat_ids = jacobian_flat_ids_.data();
processSet.jacobian_flat_ids_size = jacobian_flat_ids_.size();

std::chrono::nanoseconds kernel_duration = micm::cuda::AddJacobianTermsKernelDriver(
rate_constants.AsVector().data(),
state_variables.AsVector().data(),
rate_constants.size(), // n_grids
rate_constants[0].size(), // n_reactions
state_variables[0].size(), // n_species
jacobian.AsVector().data(),
jacobian.AsVector().size(),
number_of_reactants_.data(),
reactant_ids_.data(),
reactant_ids_.size(),
number_of_products_.data(),
yields_.data(),
yields_.size(),
jacobian_flat_ids_.data(),
jacobian_flat_ids_.size());
matrixParam,
sparseMatrix,
processSet);
return kernel_duration; // time performance of kernel function
}
} // namespace micm
Expand Down
30 changes: 30 additions & 0 deletions include/micm/util/cuda_param.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef CUDA_PARAM_HPP
#define CUDA_PARAM_HPP
//member data of class CUDAProcessSet grouped in struct passing to kernel driver function
struct CUDAProcessSetParam{
const size_t* number_of_reactants;
const size_t* reactant_ids;
size_t reactant_ids_size;
const size_t* number_of_products;
const size_t* product_ids;
size_t product_ids_size;
const double* yields;
size_t yields_size;
const size_t* jacobian_flat_ids;
size_t jacobian_flat_ids_size;
};
//different matrix data grouped in struct passing to kernel driver function
struct CUDAMatrixParam{
const double* rate_constants;
const double* state_variables;
double* forcing;
size_t n_grids;
size_t n_reactions;
size_t n_species;
};
//sparseMatrix data grouped in struct passing to kernel driver function
struct CUDASparseMatrixParam{
double* jacobian;
size_t jacobian_size;
};
#endif
Loading

0 comments on commit 12b01eb

Please sign in to comment.