#include <iostream>
static size_t dimension = 4 * 1024;
static const int maxIter = 10;
static const int sparsityFactor = 7;
void setupInputs() {
A = A * ((A % sparsityFactor) == 0) / 1000;
std::cout << "Sparsity of A = "
<< std::endl;
std::cout << "Memory Usage of A = " << A.bytes() / (1024.f * 1024.f)
<< " MB" << std::endl;
std::cout << "Memory Usage of spA = "
(1024.f * 1024.f)
<< " MB" << std::endl;
}
void sparseConjugateGradient(void) {
for (int i = 0; i < maxIter; ++i) {
array alpha = alpha_num / alpha_den;
array beta = beta_num / alpha_num;
}
}
void denseConjugateGradient(void) {
for (int i = 0; i < maxIter; ++i) {
array alpha = alpha_num / alpha_den;
array beta = beta_num / alpha_num;
}
}
void checkConjugateGradient(
const af::array in) {
for (int i = 0; i < maxIter; ++i) {
array alpha = alpha_num / alpha_den;
array beta = beta_num / alpha_num;
}
std::cout << "Final difference in solutions:\n";
}
int main(int, char **) {
setupInputs();
std::cout << "Verifying Dense Conjugate Gradient:" << std::endl;
checkConjugateGradient(A);
std::cout << "Verifying Sparse Conjugate Gradient:" << std::endl;
checkConjugateGradient(spA);
std::cout << "Dense Conjugate Gradient Time: "
<<
timeit(denseConjugateGradient) * 1000 <<
"ms" << std::endl;
std::cout << "Sparse Conjugate Gradient Time: "
<<
timeit(sparseConjugateGradient) * 1000 <<
"ms" << std::endl;
return 0;
}
A multi dimensional data container.
dim4 dims() const
Get dimensions of the array.
dim_t elements() const
Get the total number of elements across all dimensions of the array.
@ f32
32-bit floating point values
array floor(const array &in)
C++ Interface to floor numbers.
T dot(const array &lhs, const array &rhs, const matProp optLhs=AF_MAT_NONE, const matProp optRhs=AF_MAT_NONE)
C++ Interface to compute the dot product.
array matmul(const array &lhs, const array &rhs, const matProp optLhs=AF_MAT_NONE, const matProp optRhs=AF_MAT_NONE)
C++ Interface to multiply two matrices.
array transpose(const array &in, const bool conjugate=false)
C++ Interface to transpose a matrix.
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
C++ Interface to generate an array with elements set to a specified value.
array identity(const dim4 &dims, const dtype ty=f32)
C++ Interface to generate an identity array.
void sync(const int device=-1)
Blocks until the device is finished processing.
array tile(const array &in, const unsigned x, const unsigned y=1, const unsigned z=1, const unsigned w=1)
C++ Interface to generate a tiled array.
array randu(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers uniformly distributed.
array sparseGetColIdx(const array in)
array sparse(const dim_t nRows, const dim_t nCols, const array values, const array rowIdx, const array colIdx, const af::storage stype=AF_STORAGE_CSR)
This function converts array of values, row indices and column indices into a sparse array.
dim_t sparseGetNNZ(const array in)
array sparseGetRowIdx(const array in)
array sparseGetValues(const array in)
double timeit(void(*fn)())