Added C BLAS1 test
This commit is contained in:
@@ -45,107 +45,136 @@ extern "C"
|
||||
//*****************
|
||||
//BLAS1
|
||||
//*****************
|
||||
clblasStatus clblasSaxpy(size_t N, cl_float alpha,
|
||||
const cl_mem mx, size_t offx, int incx,
|
||||
cl_mem my, size_t offy, int incy,
|
||||
cl_uint numCommandQueues, cl_command_queue *commandQueues,
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList,
|
||||
cl_event *events)
|
||||
{
|
||||
is::array x(N, is::FLOAT_TYPE, cl::Buffer(mx), offx, incx);
|
||||
clRetainMemObject(mx);
|
||||
is::array y(N, is::FLOAT_TYPE, cl::Buffer(my), offy, incy);
|
||||
clRetainMemObject(my);
|
||||
execute(is::detail::assign(y, x + alpha*y), y.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);
|
||||
return clblasSuccess;
|
||||
|
||||
//AXPY
|
||||
#define MAKE_AXPY(TYPE_CHAR, TYPE_ISAAC, TYPE_CL) \
|
||||
clblasStatus clblas ## TYPE_CHAR ## axpy(size_t N, TYPE_CL alpha, \
|
||||
const cl_mem mx, size_t offx, int incx, \
|
||||
cl_mem my, size_t offy, int incy, \
|
||||
cl_uint numCommandQueues, cl_command_queue *commandQueues, \
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList, \
|
||||
cl_event *events) \
|
||||
{ \
|
||||
is::array x(N, TYPE_ISAAC, cl::Buffer(mx), offx, incx); \
|
||||
clRetainMemObject(mx); \
|
||||
is::array y(N, TYPE_ISAAC, cl::Buffer(my), offy, incy); \
|
||||
clRetainMemObject(my); \
|
||||
execute(is::detail::assign(y, x + alpha*y), y.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events); \
|
||||
return clblasSuccess; \
|
||||
}
|
||||
|
||||
clblasStatus clblasSscal(size_t N, cl_float alpha,
|
||||
cl_mem mx, size_t offx, int incx,
|
||||
cl_uint numCommandQueues, cl_command_queue *commandQueues,
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)
|
||||
{
|
||||
is::array x(N, is::FLOAT_TYPE, cl::Buffer(mx), offx, incx);
|
||||
clRetainMemObject(mx);
|
||||
execute(is::detail::assign(x, alpha*x), x.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);
|
||||
return clblasSuccess;
|
||||
MAKE_AXPY(S, is::FLOAT_TYPE, cl_float)
|
||||
MAKE_AXPY(D, is::DOUBLE_TYPE, cl_double)
|
||||
|
||||
//SCAL
|
||||
#define MAKE_SCAL(TYPE_CHAR, TYPE_ISAAC, TYPE_CL) \
|
||||
clblasStatus clblas ## TYPE_CHAR ## scal(size_t N, TYPE_CL alpha,\
|
||||
cl_mem mx, size_t offx, int incx,\
|
||||
cl_uint numCommandQueues, cl_command_queue *commandQueues,\
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)\
|
||||
{\
|
||||
is::array x(N, TYPE_ISAAC, cl::Buffer(mx), offx, incx);\
|
||||
clRetainMemObject(mx);\
|
||||
execute(is::detail::assign(x, alpha*x), x.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);\
|
||||
return clblasSuccess;\
|
||||
}
|
||||
|
||||
clblasStatus clblasScopy(size_t N,
|
||||
const cl_mem mx, size_t offx, int incx,
|
||||
cl_mem my, size_t offy, int incy,
|
||||
cl_uint numCommandQueues, cl_command_queue *commandQueues,
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)
|
||||
{
|
||||
const is::array x(N, is::FLOAT_TYPE, cl::Buffer(mx), offx, incx);
|
||||
clRetainMemObject(mx);
|
||||
is::array y(N, is::FLOAT_TYPE, cl::Buffer(my), offy, incy);
|
||||
clRetainMemObject(my);
|
||||
execute(is::detail::assign(y, x), y.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);
|
||||
return clblasSuccess;
|
||||
MAKE_SCAL(S, is::FLOAT_TYPE, cl_float)
|
||||
MAKE_SCAL(D, is::DOUBLE_TYPE, cl_double)
|
||||
|
||||
//COPY
|
||||
#define MAKE_COPY(TYPE_CHAR, TYPE_ISAAC, TYPE_CL)\
|
||||
clblasStatus clblas ## TYPE_CHAR ## copy(size_t N,\
|
||||
const cl_mem mx, size_t offx, int incx,\
|
||||
cl_mem my, size_t offy, int incy,\
|
||||
cl_uint numCommandQueues, cl_command_queue *commandQueues,\
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)\
|
||||
{\
|
||||
const is::array x(N, TYPE_ISAAC, cl::Buffer(mx), offx, incx);\
|
||||
clRetainMemObject(mx);\
|
||||
is::array y(N, TYPE_ISAAC, cl::Buffer(my), offy, incy);\
|
||||
clRetainMemObject(my);\
|
||||
execute(is::detail::assign(y, x), y.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);\
|
||||
return clblasSuccess;\
|
||||
}
|
||||
|
||||
clblasStatus clblasSdot(size_t N, cl_mem dotProduct, size_t offDP,
|
||||
const cl_mem mx, size_t offx, int incx,
|
||||
const cl_mem my, size_t offy, int incy,
|
||||
cl_mem /*scratchBuff*/, cl_uint numCommandQueues,
|
||||
cl_command_queue *commandQueues, cl_uint numEventsInWaitList,
|
||||
const cl_event *eventWaitList, cl_event *events)
|
||||
{
|
||||
is::array x(N, is::FLOAT_TYPE, cl::Buffer(mx), offx, incx);
|
||||
clRetainMemObject(mx);
|
||||
is::array y(N, is::FLOAT_TYPE, cl::Buffer(my), offy, incy);
|
||||
clRetainMemObject(my);
|
||||
is::scalar s(is::FLOAT_TYPE, cl::Buffer(dotProduct), offDP);
|
||||
clRetainMemObject(dotProduct);
|
||||
execute(is::detail::assign(s, dot(x,y)), s.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);
|
||||
return clblasSuccess;
|
||||
MAKE_COPY(S, is::FLOAT_TYPE, cl_float)
|
||||
MAKE_COPY(D, is::DOUBLE_TYPE, cl_double)
|
||||
|
||||
//DOT
|
||||
#define MAKE_DOT(TYPE_CHAR, TYPE_ISAAC, TYPE_CL) \
|
||||
clblasStatus clblas ## TYPE_CHAR ## dot(size_t N, cl_mem dotProduct, size_t offDP, \
|
||||
const cl_mem mx, size_t offx, int incx, \
|
||||
const cl_mem my, size_t offy, int incy, \
|
||||
cl_mem /*scratchBuff*/, cl_uint numCommandQueues, \
|
||||
cl_command_queue *commandQueues, cl_uint numEventsInWaitList, \
|
||||
const cl_event *eventWaitList, cl_event *events) \
|
||||
{ \
|
||||
is::array x(N, TYPE_ISAAC, cl::Buffer(mx), offx, incx); \
|
||||
clRetainMemObject(mx); \
|
||||
is::array y(N, TYPE_ISAAC, cl::Buffer(my), offy, incy); \
|
||||
clRetainMemObject(my); \
|
||||
is::scalar s(TYPE_ISAAC, cl::Buffer(dotProduct), offDP); \
|
||||
clRetainMemObject(dotProduct); \
|
||||
execute(is::detail::assign(s, dot(x,y)), s.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events); \
|
||||
return clblasSuccess; \
|
||||
}
|
||||
|
||||
clblasStatus clblasSasum(size_t N, cl_mem asum, size_t offAsum,
|
||||
const cl_mem mx, size_t offx, int incx,
|
||||
cl_mem /*scratchBuff*/, cl_uint numCommandQueues, cl_command_queue *commandQueues,
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)
|
||||
{
|
||||
is::array x(N, is::FLOAT_TYPE, cl::Buffer(mx), offx, incx);
|
||||
clRetainMemObject(mx);
|
||||
is::scalar s(is::FLOAT_TYPE, cl::Buffer(asum), offAsum);
|
||||
clRetainMemObject(asum);
|
||||
execute(is::detail::assign(s, sum(abs(x))), s.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);
|
||||
return clblasSuccess;
|
||||
MAKE_DOT(S, is::FLOAT_TYPE, cl_float)
|
||||
MAKE_DOT(D, is::DOUBLE_TYPE, cl_double)
|
||||
|
||||
//ASUM
|
||||
#define MAKE_ASUM(TYPE_CHAR, TYPE_ISAAC, TYPE_CL) \
|
||||
clblasStatus clblas ## TYPE_CHAR ## asum(size_t N, cl_mem asum, size_t offAsum, \
|
||||
const cl_mem mx, size_t offx, int incx,\
|
||||
cl_mem /*scratchBuff*/, cl_uint numCommandQueues, cl_command_queue *commandQueues,\
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)\
|
||||
{\
|
||||
is::array x(N, TYPE_ISAAC, cl::Buffer(mx), offx, incx);\
|
||||
clRetainMemObject(mx);\
|
||||
is::scalar s(TYPE_ISAAC, cl::Buffer(asum), offAsum);\
|
||||
clRetainMemObject(asum);\
|
||||
execute(is::detail::assign(s, sum(abs(x))), s.context(), numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);\
|
||||
return clblasSuccess;\
|
||||
}
|
||||
|
||||
MAKE_ASUM(S, is::FLOAT_TYPE, cl_float)
|
||||
MAKE_ASUM(D, is::DOUBLE_TYPE, cl_double)
|
||||
|
||||
//*****************
|
||||
//BLAS2
|
||||
//*****************
|
||||
clblasStatus clblasSgemv(clblasOrder order, clblasTranspose transA,
|
||||
size_t M, size_t N,
|
||||
cl_float alpha, const cl_mem mA, size_t offA, size_t lda,
|
||||
const cl_mem mx, size_t offx, int incx,
|
||||
cl_float beta, cl_mem my, size_t offy, int incy,
|
||||
cl_uint numCommandQueues, cl_command_queue *commandQueues,
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)
|
||||
{
|
||||
//A
|
||||
is::int_t As1 = M, As2 = N;
|
||||
if(transA==clblasTrans) std::swap(As1, As2);
|
||||
is::array A(As1, As2, is::FLOAT_TYPE, cl::Buffer(mA), offA, lda);
|
||||
clRetainMemObject(mA);
|
||||
//x
|
||||
is::array x(N, is::FLOAT_TYPE, cl::Buffer(mx), offx, incx);
|
||||
clRetainMemObject(mx);
|
||||
//y
|
||||
is::array y(N, is::FLOAT_TYPE, cl::Buffer(my), offy, incy);
|
||||
clRetainMemObject(my);
|
||||
//Operation
|
||||
is::driver::Context const & context = A.context();
|
||||
if(transA==clblasTrans)
|
||||
execute(is::detail::assign(y, alpha*dot(A.T(), x) + beta*y), context, numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);
|
||||
else
|
||||
execute(is::detail::assign(y, alpha*dot(A, x) + beta*y), context, numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);
|
||||
return clblasSuccess;
|
||||
#define MAKE_GEMV(TYPE_CHAR, TYPE_ISAAC, TYPE_CL) \
|
||||
clblasStatus clblas ## TYPE_CHAR ## gemv(clblasOrder order, clblasTranspose transA,\
|
||||
size_t M, size_t N,\
|
||||
TYPE_CL alpha, const cl_mem mA, size_t offA, size_t lda,\
|
||||
const cl_mem mx, size_t offx, int incx,\
|
||||
TYPE_CL beta, cl_mem my, size_t offy, int incy,\
|
||||
cl_uint numCommandQueues, cl_command_queue *commandQueues,\
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events)\
|
||||
{\
|
||||
is::int_t As1 = M, As2 = N;\
|
||||
if(transA==clblasTrans) std::swap(As1, As2);\
|
||||
is::array A(As1, As2, TYPE_ISAAC, cl::Buffer(mA), offA, lda);\
|
||||
clRetainMemObject(mA);\
|
||||
\
|
||||
is::array x(N, TYPE_ISAAC, cl::Buffer(mx), offx, incx);\
|
||||
clRetainMemObject(mx);\
|
||||
\
|
||||
is::array y(N, TYPE_ISAAC, cl::Buffer(my), offy, incy);\
|
||||
clRetainMemObject(my);\
|
||||
\
|
||||
is::driver::Context const & context = A.context();\
|
||||
if((transA==clblasTrans) ^ (order==clblasRowMajor))\
|
||||
execute(is::detail::assign(y, alpha*dot(A.T(), x) + beta*y), context, numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);\
|
||||
else\
|
||||
execute(is::detail::assign(y, alpha*dot(A, x) + beta*y), context, numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events);\
|
||||
return clblasSuccess;\
|
||||
}
|
||||
|
||||
MAKE_GEMV(S, is::FLOAT_TYPE, cl_float)
|
||||
MAKE_GEMV(D, is::DOUBLE_TYPE, cl_double)
|
||||
|
||||
//*****************
|
||||
//BLAS3
|
||||
//*****************
|
||||
|
Reference in New Issue
Block a user