| 67 | |
| 68 | template<typename T> |
| 69 | static void sparseTester(const int m, const int n, const int k, int factor, |
| 70 | double eps, int targetDevice = -1) { |
| 71 | if (targetDevice >= 0) af::setDevice(targetDevice); |
| 72 | |
| 73 | af::deviceGC(); |
| 74 | |
| 75 | SUPPORTED_TYPE_CHECK(T); |
| 76 | |
| 77 | #if 1 |
| 78 | af::array A = cpu_randu<T>(af::dim4(m, n)); |
| 79 | af::array B = cpu_randu<T>(af::dim4(n, k)); |
| 80 | #else |
| 81 | af::array A = af::randu(m, n, (af::dtype)af::dtype_traits<T>::af_type); |
| 82 | af::array B = af::randu(n, k, (af::dtype)af::dtype_traits<T>::af_type); |
| 83 | #endif |
| 84 | |
| 85 | A = makeSparse<T>(A, factor); |
| 86 | |
| 87 | // Result of GEMM |
| 88 | af::array dRes1 = matmul(A, B); |
| 89 | |
| 90 | // Create Sparse Array From Dense |
| 91 | af::array sA = af::sparse(A, AF_STORAGE_CSR); |
| 92 | |
| 93 | // Sparse Matmul |
| 94 | af::array sRes1 = matmul(sA, B); |
| 95 | |
| 96 | // Verify Results |
| 97 | ASSERT_NEAR(0, calc_norm(real(dRes1), real(sRes1)), eps); |
| 98 | ASSERT_NEAR(0, calc_norm(imag(dRes1), imag(sRes1)), eps); |
| 99 | } |
| 100 | |
| 101 | template<typename T> |
| 102 | static void sparseTransposeTester(const int m, const int n, const int k, |