Files
triton/tests/mreduction.cpp

81 lines
2.2 KiB
C++
Raw Normal View History

#include <cmath>
#include "common.hpp"
#include "atidlas/array.h"
namespace ad = atidlas;
template<typename T>
void test_row_wise_reduction(T epsilon, simple_vector_base<T> & cy, simple_matrix_base<T> const & cA, simple_vector_base<T> & cx,
ad::array & y, ad::array const & A, ad::array & x)
{
int failure_count = 0;
2015-01-17 15:47:52 -05:00
ad::int_t M = A.shape()._1;
ad::int_t N = A.shape()._2;
2015-01-17 15:47:52 -05:00
simple_vector<T> bufy(M);
simple_vector<T> bufx(N);
T yi = 0, xi = 0;
2015-01-17 15:47:52 -05:00
#define TEST_OPERATION(NAME, SIZE1, SIZE2, REDUCTION, ASSIGNMENT, GPU_REDUCTION, RES, BUF, CRES)\
std::cout << NAME "..." << std::flush;\
for(int i = 0 ; i < SIZE1 ; ++i)\
{\
yi = 0;\
xi = 0;\
for(int j = 0 ; j < SIZE2 ; ++j)\
REDUCTION;\
ASSIGNMENT;\
}\
GPU_REDUCTION;\
2015-01-17 15:47:52 -05:00
ad::copy(RES, BUF.data());\
2015-01-29 15:19:40 -05:00
if(diff(CRES, BUF, epsilon))\
{\
failure_count++;\
std::cout << " [Failure!]" << std::endl;\
}\
else\
std::cout << std::endl;
2015-01-17 15:47:52 -05:00
TEST_OPERATION("y = A.x", M, N, yi+=cA(i,j)*cx[j], cy[i] = yi, y = dot(A,x), y, bufy, cy);
TEST_OPERATION("x = A'.y", N, M, xi+=cA(j,i)*cy[j], cx[i] = xi, x = dot(trans(A),y), x, bufx, cx);
if(failure_count>0)
exit(EXIT_FAILURE);
}
template<typename T>
2015-01-27 16:14:02 -05:00
void test_impl(T epsilon, cl::Context const & ctx)
{
int_t M = 1324;
int_t N = 1143;
int_t SUBM = 184;
int_t SUBN = 145;
2015-01-19 14:40:13 -05:00
INIT_MATRIX(M, SUBM, 5, 3, N, SUBN, 7, 2, cA, A, ctx);
INIT_VECTOR(M, SUBM, 6, 2, cy, y, ctx);
INIT_VECTOR(N, SUBN, 4, 3, cx, x, ctx);
2015-01-18 14:52:45 -05:00
std::cout << "full..." << std::endl;
test_row_wise_reduction(epsilon, cy_full, cA_full, cx_full, y_full, A_full, x_full);
2015-01-17 15:47:52 -05:00
std::cout << "slice..." << std::endl;
test_row_wise_reduction(epsilon, cy_slice, cA_slice, cx_slice, y_slice, A_slice, x_slice);
}
int main()
{
2015-02-04 22:06:15 -05:00
for(const auto & elem : ad::cl_ext::queues.data())
2015-01-19 14:40:13 -05:00
{
2015-02-04 22:06:15 -05:00
cl::Device device = elem.second[0].getInfo<CL_QUEUE_DEVICE>();
2015-01-19 14:40:13 -05:00
std::cout << "Device: " << device.getInfo<CL_DEVICE_NAME>() << std::endl;
std::cout << "---" << std::endl;
std::cout << ">> float" << std::endl;
2015-02-04 22:06:15 -05:00
test_impl<float>(1e-4, elem.first);
2015-01-19 14:40:13 -05:00
std::cout << ">> double" << std::endl;
2015-02-04 22:06:15 -05:00
test_impl<double>(1e-9, elem.first);
2015-01-19 14:40:13 -05:00
std::cout << "---" << std::endl;
}
return EXIT_SUCCESS;
}