Commit c77da5d2 authored by Radford Neal's avatar Radford Neal

Merge branch '74-matprod' into 80-perf

parents 2eafb9e3 c729602a
......@@ -25,18 +25,18 @@
/* NAMES OF TASKS. The list below has to be manually updated when new
task procedures are defined. */
#define TASK_NAME(n) \
do { \
extern helpers_task_proc task_##n; \
if (task == &task_##n) return #n; \
} while (0)
char *Rf_task_name (helpers_task_proc *task)
{
/* Put one line here for every task procedure used. Names of task
procedures should start with "task_". The part of the name
after "task_" should be given as the argument to TASK_NAME below. */
# define TASK_NAME(n) \
do { \
extern helpers_task_proc task_##n; \
if (task == &task_##n) return #n; \
} while (0)
TASK_NAME(row_or_col);
/* a */
TASK_NAME(rowSums_or_rowMeans);
......@@ -76,6 +76,7 @@ char *Rf_task_name (helpers_task_proc *task)
TASK_NAME(par_matprod_vec_vec);
TASK_NAME(par_matprod_mat_vec);
TASK_NAME(par_matprod_vec_mat);
TASK_NAME(par_matprod_outer);
TASK_NAME(par_matprod_mat_mat);
/* s */
TASK_NAME(matprod_trans1);
......
......@@ -338,7 +338,7 @@ negative value can be used for "split", in which case the negative of
splitting is not possible (given implementation constraints). A value
of zero for "split" indicates that the corresponding matprod procedure
should be called immediately without scheduling a task, after waiting
for the second operand to be computed if it has not been already.
for the operands to be computed if they have not been already.
If the final 'pipe' argument is non-zero, the tasks scheduled by the
par_matprod procedures use pipelining for the second operand and the
......
......@@ -812,7 +812,7 @@ void par_matprod_scalar_vec (helpers_var_ptr z, helpers_var_ptr x,
helpers_size_t m = LENGTH(z);
if (split == 0)
{ helpers_wait_until_not_being_computed(y);
{ helpers_wait_until_not_being_computed2(x,y);
matprod_scalar_vec (*REAL(x), REAL(y), REAL(z), m EXTRAZ);
return;
}
......@@ -845,7 +845,7 @@ void par_matprod_vec_vec (helpers_var_ptr z, helpers_var_ptr x,
helpers_size_t k = LENGTH(x);
if (split == 0)
{ helpers_wait_until_not_being_computed(y);
{ helpers_wait_until_not_being_computed2(x,y);
REAL(z)[0] = matprod_vec_vec (REAL(x), REAL(y), k);
return;
}
......@@ -865,7 +865,7 @@ void par_matprod_vec_mat (helpers_var_ptr z, helpers_var_ptr x,
helpers_size_t m = LENGTH(z);
if (split == 0)
{ helpers_wait_until_not_being_computed(y);
{ helpers_wait_until_not_being_computed2(x,y);
matprod_vec_mat (REAL(x), REAL(y), REAL(z), k, m EXTRAZ);
return;
}
......@@ -899,7 +899,7 @@ void par_matprod_mat_vec (helpers_var_ptr z, helpers_var_ptr x,
helpers_size_t k = LENGTH(y);
if (split == 0)
{ helpers_wait_until_not_being_computed(y);
{ helpers_wait_until_not_being_computed2(x,y);
matprod_mat_vec (REAL(x), REAL(y), REAL(z), n, k);
return;
}
......@@ -935,7 +935,7 @@ void par_matprod_outer (helpers_var_ptr z, helpers_var_ptr x,
helpers_size_t m = LENGTH(y);
if (split == 0)
{ helpers_wait_until_not_being_computed(y);
{ helpers_wait_until_not_being_computed2(x,y);
matprod_outer (REAL(x), REAL(y), REAL(z), n, m EXTRAZ);
return;
}
......@@ -969,7 +969,7 @@ void par_matprod_mat_mat (helpers_var_ptr z, helpers_var_ptr x,
helpers_size_t m = LENGTH(y) / k;
if (split == 0)
{ helpers_wait_until_not_being_computed(y);
{ helpers_wait_until_not_being_computed2(x,y);
matprod_mat_mat (REAL(x), REAL(y), REAL(z), n, k, m EXTRAZ);
return;
}
......@@ -1003,7 +1003,7 @@ void par_matprod_trans1 (helpers_var_ptr z, helpers_var_ptr x,
helpers_size_t m = LENGTH(y) / k;
if (split == 0)
{ helpers_wait_until_not_being_computed(y);
{ helpers_wait_until_not_being_computed2(x,y);
matprod_trans1 (REAL(x), REAL(y), REAL(z), n, k, m EXTRAZ);
return;
}
......@@ -1037,7 +1037,7 @@ void par_matprod_trans2 (helpers_var_ptr z, helpers_var_ptr x,
helpers_size_t m = LENGTH(y) / k;
if (split == 0)
{ helpers_wait_until_not_being_computed(y);
{ helpers_wait_until_not_being_computed2(x,y);
matprod_trans2 (REAL(x), REAL(y), REAL(z), n, k, m EXTRAZ);
return;
}
......@@ -1071,7 +1071,7 @@ void par_matprod_trans12 (helpers_var_ptr z, helpers_var_ptr x,
helpers_size_t m = LENGTH(y) / k;
if (split == 0)
{ helpers_wait_until_not_being_computed(y);
{ helpers_wait_until_not_being_computed2(x,y);
matprod_trans12 (REAL(x), REAL(y), REAL(z), n, k, m);
return;
}
......
......@@ -959,11 +959,13 @@ static SEXP do_matprod (SEXP call, SEXP op, SEXP args, SEXP rho, int variant)
/* Compute the result matrix. */
int inhlpr = nrows*(k+1.0)*ncols > T_matmult;
int no_pipelining = !inhlpr || helpers_not_pipelining_now;
int pipeline = inhlpr && !helpers_not_pipelining_now;
int no_pipelining = !pipeline;
int split = !inhlpr || helpers_not_multithreading_now ? 0 : helpers_num+1;
SEXP op1 = x, op2 = y;
int flags = 0;
helpers_task_proc *task_proc;
helpers_task_proc *task_proc = 0;
int flags = 0;
ans = allocMatrix0 (mode, nrows, ncols);
......@@ -1027,12 +1029,8 @@ static SEXP do_matprod (SEXP call, SEXP op, SEXP args, SEXP rho, int variant)
task_proc = task_matprod_vec_vec_BLAS;
if (!R_BLAS_in_helpers) inhlpr = 0;
}
else if (no_pipelining)
task_proc = task_matprod_vec_vec;
else {
task_proc = task_par_matprod_vec_vec;
flags = HELPERS_PIPE_IN2;
}
else
par_matprod_vec_vec (ans, op1, op2, split, pipeline);
}
else if (primop == 0) { /* %*%, real, not dot product, not null or 0s */
......@@ -1041,36 +1039,26 @@ static SEXP do_matprod (SEXP call, SEXP op, SEXP args, SEXP rho, int variant)
task_proc = task_matprod_mat_vec_BLAS;
if (!R_BLAS_in_helpers) inhlpr = 0;
}
else if (no_pipelining)
task_proc = task_matprod_mat_vec;
else {
task_proc = task_par_matprod_mat_vec;
flags = HELPERS_PIPE_IN2;
}
else
par_matprod_mat_vec (ans, op1, op2, split, pipeline);
}
else if (nrows==1) {
if (R_mat_mult_with_BLAS[2] == 1) {
task_proc = task_matprod_vec_mat_BLAS;
if (!R_BLAS_in_helpers) inhlpr = 0;
}
else if (no_pipelining)
task_proc = task_matprod_vec_mat;
else {
task_proc = task_par_matprod_vec_mat;
flags = HELPERS_PIPE_IN2_OUT;
}
else
par_matprod_vec_mat (ans, op1, op2, split, pipeline);
}
else if (k == 1 && use_BLAS == 0)
par_matprod_outer (ans, op1, op2, split, pipeline);
else {
if (use_BLAS != 0) /* will always be 0 or 1, never NA */ {
task_proc = task_matprod_mat_mat_BLAS;
if (!R_BLAS_in_helpers) inhlpr = 0;
}
else if (no_pipelining)
task_proc = task_matprod_mat_mat;
else {
task_proc = task_par_matprod_mat_mat;
flags = HELPERS_PIPE_IN2_OUT;
}
else
par_matprod_mat_mat (ans, op1, op2, k, split, pipeline);
}
}
......@@ -1082,12 +1070,8 @@ static SEXP do_matprod (SEXP call, SEXP op, SEXP args, SEXP rho, int variant)
task_proc = task_matprod_vec_mat_BLAS;
if (!R_BLAS_in_helpers) inhlpr = 0;
}
else if (no_pipelining)
task_proc = task_matprod_vec_mat;
else {
task_proc = task_par_matprod_vec_mat;
flags = HELPERS_PIPE_IN2_OUT;
}
else
par_matprod_vec_mat (ans, op1, op2, split, pipeline);
}
else {
if (nrows==1) { op1 = y; op2 = x; }
......@@ -1095,12 +1079,8 @@ static SEXP do_matprod (SEXP call, SEXP op, SEXP args, SEXP rho, int variant)
task_proc = task_matprod_mat_vec_BLAS;
if (!R_BLAS_in_helpers) inhlpr = 0;
}
else if (no_pipelining)
task_proc = task_matprod_mat_vec;
else {
task_proc = task_par_matprod_mat_vec;
flags = HELPERS_PIPE_IN2;
}
else
par_matprod_mat_vec (ans, op1, op2, split, pipeline);
}
}
else {
......@@ -1109,23 +1089,21 @@ static SEXP do_matprod (SEXP call, SEXP op, SEXP args, SEXP rho, int variant)
: task_matprod_trans2_BLAS;
if (!R_BLAS_in_helpers) inhlpr = 0;
}
else if (no_pipelining)
task_proc = primop==1 ? task_matprod_trans1
: task_matprod_trans2;
else {
if (primop==1) {
task_proc = task_par_matprod_trans1;
flags = HELPERS_PIPE_IN2_OUT;
}
else {
task_proc = task_par_matprod_trans2;
flags = HELPERS_PIPE_OUT;
}
}
else if (primop == 1)
par_matprod_trans1 (ans, op1, op2, k, split, pipeline);
else
par_matprod_trans2 (ans, op1, op2, k, split, pipeline);
}
}
DO_NOW_OR_LATER2 (variant, inhlpr, flags, task_proc, k, ans, op1, op2);
if (task_proc != 0) {
DO_NOW_OR_LATER2 (variant, inhlpr, flags, task_proc,
k, ans, op1, op2);
}
else {
if (split != 0 && ! (variant & VARIANT_PENDING_OK))
WAIT_UNTIL_COMPUTED(ans);
}
}
PROTECT(ans = allocMatrix1 (ans, nrows, ncols));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment