32 #include "rt-accumulator.h"
34 #include "runtime-hclib.h"
50 void (*op)(
short * res,
short cur,
short new);
53 void accum_op_short_max(
short * res,
short cur,
short new) {
59 void accum_op_short_min(
short * res,
short cur,
short new) {
65 void accum_op_short_plus(
short * res,
short cur,
short new) {
69 void accum_op_short_prod(
short * res,
short cur,
short new) {
73 void accum_op_short_land(
short * res,
short cur,
short new) {
77 void accum_op_short_band(
short * res,
short cur,
short new) {
81 void accum_op_short_lor(
short * res,
short cur,
short new) {
85 void accum_op_short_bor(
short * res,
short cur,
short new) {
89 void accum_op_short_lxor(
short * res,
short cur,
short new) {
93 void accum_op_short_bxor(
short * res,
short cur,
short new) {
100 void (*open)(
struct accum_int_t * accum,
int init);
103 void (*op)(
int * res,
int cur,
int new);
106 void accum_op_int_max(
int * res,
int cur,
int new) {
112 void accum_op_int_min(
int * res,
int cur,
int new) {
118 void accum_op_int_plus(
int * res,
int cur,
int new) {
122 void accum_op_int_prod(
int * res,
int cur,
int new) {
126 void accum_op_int_land(
int * res,
int cur,
int new) {
130 void accum_op_int_band(
int * res,
int cur,
int new) {
134 void accum_op_int_lor(
int * res,
int cur,
int new) {
138 void accum_op_int_bor(
int * res,
int cur,
int new) {
142 void accum_op_int_lxor(
int * res,
int cur,
int new) {
146 void accum_op_int_bxor(
int * res,
int cur,
int new) {
156 void (*op)(
long * res,
long cur,
long new);
159 void accum_op_long_max(
long * res,
long cur,
long new) {
165 void accum_op_long_min(
long * res,
long cur,
long new) {
171 void accum_op_long_plus(
long * res,
long cur,
long new) {
175 void accum_op_long_prod(
long * res,
long cur,
long new) {
179 void accum_op_long_land(
long * res,
long cur,
long new) {
183 void accum_op_long_band(
long * res,
long cur,
long new) {
187 void accum_op_long_lor(
long * res,
long cur,
long new) {
191 void accum_op_long_bor(
long * res,
long cur,
long new) {
195 void accum_op_long_lxor(
long * res,
long cur,
long new) {
199 void accum_op_long_bxor(
long * res,
long cur,
long new) {
209 void (*op)(
float * res,
float cur,
float new);
212 void accum_op_float_max(
float * res,
float cur,
float new) {
218 void accum_op_float_min(
float * res,
float cur,
float new) {
224 void accum_op_float_plus(
float * res,
float cur,
float new) {
228 void accum_op_float_prod(
float * res,
float cur,
float new) {
238 void (*op)(
double * res,
double cur,
double new);
241 void accum_op_double_max(
double * res,
double cur,
double new) {
247 void accum_op_double_min(
double * res,
double cur,
double new) {
253 void accum_op_double_plus(
double * res,
double cur,
double new) {
257 void accum_op_double_prod(
double * res,
double cur,
double new) {
278 short * result = &(accum_short->result);
281 int nb_w = get_nb_workers();
284 accum_short->op(result, *result, localAccums[i]);
294 void accum_open_short_lazy(
accum_short_t * accum,
short init) {
295 accum->result = init;
296 int nb_w = get_nb_workers();
299 short * localAccums = malloc(
sizeof(
short) * nb_w);
302 localAccums[i] = init;
305 accum_lazy->localAccums = localAccums;
309 int wid = get_worker_id_hc();
311 return accum->op(&(accum_lazy->localAccums[wid]), accum_lazy->localAccums[wid], v);
315 return accum->result;
331 int * result = &(accum_int->result);
334 int nb_w = get_nb_workers();
337 accum_int->op(result, *result, localAccums[i]);
347 void accum_open_int_lazy(
accum_int_t * accum,
int init) {
348 accum->result = init;
349 int nb_w = get_nb_workers();
352 int * localAccums = malloc(
sizeof(
int) * nb_w);
355 localAccums[i] = init;
358 accum_lazy->localAccums = localAccums;
361 void accum_put_int_lazy(
accum_int_t * accum,
int v) {
362 int wid = get_worker_id_hc();
364 return accum->op(&(accum_lazy->localAccums[wid]), accum_lazy->localAccums[wid], v);
368 return accum->result;
384 long * result = &(accum_long->result);
387 int nb_w = get_nb_workers();
390 accum_long->op(result, *result, localAccums[i]);
400 void accum_open_long_lazy(
accum_long_t * accum,
long init) {
401 accum->result = init;
402 int nb_w = get_nb_workers();
405 long * localAccums = malloc(
sizeof(
long) * nb_w);
408 localAccums[i] = init;
411 accum_lazy->localAccums = localAccums;
414 void accum_put_long_lazy(
accum_long_t * accum,
long v) {
415 int wid = get_worker_id_hc();
417 return accum->op(&(accum_lazy->localAccums[wid]), accum_lazy->localAccums[wid], v);
421 return accum->result;
437 float * result = &(accum_float->result);
440 int nb_w = get_nb_workers();
443 accum_float->op(result, *result, localAccums[i]);
453 void accum_open_float_lazy(
accum_float_t * accum,
float init) {
454 accum->result = init;
455 int nb_w = get_nb_workers();
458 float * localAccums = malloc(
sizeof(
float) * nb_w);
461 localAccums[i] = init;
464 accum_lazy->localAccums = localAccums;
468 int wid = get_worker_id_hc();
470 return accum->op(&(accum_lazy->localAccums[wid]), accum_lazy->localAccums[wid], v);
474 return accum->result;
479 double * localAccums;
490 double * result = &(accum_double->result);
493 int nb_w = get_nb_workers();
496 accum_double->op(result, *result, localAccums[i]);
501 accum_t * accum_transmit_double_lazy(
accum_impl_t * accum,
void * params,
int properties) {
506 void accum_open_double_lazy(
accum_double_t * accum,
double init) {
507 accum->result = init;
508 int nb_w = get_nb_workers();
511 double * localAccums = malloc(
sizeof(
double) * nb_w);
514 localAccums[i] = init;
517 accum_lazy->localAccums = localAccums;
521 int wid = get_worker_id_hc();
523 return accum->op(&(accum_lazy->localAccums[wid]), accum_lazy->localAccums[wid], v);
527 return accum->result;
536 if(mode == ACCUM_MODE_SEQ) {
546 }
else if(mode == ACCUM_MODE_REC) {
560 }
else if(mode == ACCUM_MODE_LAZY) {
563 accum_lazy->localAccums = NULL;
566 accum_impl->close = accum_close_short_lazy;
567 accum_impl->transmit = accum_transmit_short_lazy;
568 accum_impl->destroy = accum_destroy_short_lazy;
569 accum_short->open = accum_open_short_lazy;
570 accum_short->get = accum_get_short_lazy;
571 accum_short->put = accum_put_short_lazy;
573 assert(0 &&
"error: short accumulator mode not implemented");
581 accum_short->op = accum_op_short_max;
584 accum_short->op = accum_op_short_min;
587 accum_short->op = accum_op_short_plus;
590 accum_short->op = accum_op_short_prod;
593 accum_short->op = accum_op_short_land;
596 accum_short->op = accum_op_short_band;
599 accum_short->op = accum_op_short_lor;
602 accum_short->op = accum_op_short_bor;
605 accum_short->op = accum_op_short_lxor;
608 accum_short->op = accum_op_short_bxor;
611 assert(0 &&
"error: short accumulator operation not implemented");
615 accum_short->open(accum_short, init);
616 return (
accum_t *) accum_short;
621 if(mode == ACCUM_MODE_SEQ) {
631 }
else if(mode == ACCUM_MODE_REC) {
645 }
else if(mode == ACCUM_MODE_LAZY) {
648 accum_lazy->localAccums = NULL;
651 accum_impl->close = accum_close_int_lazy;
652 accum_impl->transmit = accum_transmit_int_lazy;
653 accum_impl->destroy = accum_destroy_int_lazy;
654 accum_int->open = accum_open_int_lazy;
655 accum_int->get = accum_get_int_lazy;
656 accum_int->put = accum_put_int_lazy;
658 assert(0 &&
"error: int accumulator mode not implemented");
666 accum_int->op = accum_op_int_max;
669 accum_int->op = accum_op_int_min;
672 accum_int->op = accum_op_int_plus;
675 accum_int->op = accum_op_int_prod;
678 accum_int->op = accum_op_int_land;
681 accum_int->op = accum_op_int_band;
684 accum_int->op = accum_op_int_lor;
687 accum_int->op = accum_op_int_bor;
690 accum_int->op = accum_op_int_lxor;
693 accum_int->op = accum_op_int_bxor;
696 assert(0 &&
"error: int accumulator operation not implemented");
700 accum_int->open(accum_int, init);
705 if(mode == ACCUM_MODE_SEQ) {
715 }
else if(mode == ACCUM_MODE_REC) {
729 }
else if(mode == ACCUM_MODE_LAZY) {
732 accum_lazy->localAccums = NULL;
735 accum_impl->close = accum_close_long_lazy;
736 accum_impl->transmit = accum_transmit_long_lazy;
737 accum_impl->destroy = accum_destroy_long_lazy;
738 accum_long->open = accum_open_long_lazy;
739 accum_long->get = accum_get_long_lazy;
740 accum_long->put = accum_put_long_lazy;
742 assert(0 &&
"error: long accumulator mode not implemented");
750 accum_long->op = accum_op_long_max;
753 accum_long->op = accum_op_long_min;
756 accum_long->op = accum_op_long_plus;
759 accum_long->op = accum_op_long_prod;
762 accum_long->op = accum_op_long_land;
765 accum_long->op = accum_op_long_band;
768 accum_long->op = accum_op_long_lor;
771 accum_long->op = accum_op_long_bor;
774 accum_long->op = accum_op_long_lxor;
777 accum_long->op = accum_op_long_bxor;
780 assert(0 &&
"error: long accumulator operation not implemented");
784 accum_long->open(accum_long, init);
789 if(mode == ACCUM_MODE_SEQ) {
799 }
else if(mode == ACCUM_MODE_REC) {
813 }
else if(mode == ACCUM_MODE_LAZY) {
816 accum_lazy->localAccums = NULL;
819 accum_impl->close = accum_close_float_lazy;
820 accum_impl->transmit = accum_transmit_float_lazy;
821 accum_impl->destroy = accum_destroy_float_lazy;
822 accum_float->open = accum_open_float_lazy;
823 accum_float->get = accum_get_float_lazy;
824 accum_float->put = accum_put_float_lazy;
826 assert(0 &&
"error: float accumulator mode not implemented");
834 accum_float->op = accum_op_float_max;
837 accum_float->op = accum_op_float_min;
840 accum_float->op = accum_op_float_plus;
843 accum_float->op = accum_op_float_prod;
846 assert(0 &&
"error: float accumulator operation not implemented");
850 accum_float->open(accum_float, init);
851 return (
accum_t *) accum_float;
855 if(mode == ACCUM_MODE_SEQ) {
865 }
else if(mode == ACCUM_MODE_REC) {
879 }
else if(mode == ACCUM_MODE_LAZY) {
882 accum_lazy->localAccums = NULL;
885 accum_impl->close = accum_close_double_lazy;
886 accum_impl->transmit = accum_transmit_double_lazy;
887 accum_impl->destroy = accum_destroy_double_lazy;
888 accum_double->open = accum_open_double_lazy;
889 accum_double->get = accum_get_double_lazy;
890 accum_double->put = accum_put_double_lazy;
892 assert(0 &&
"error: double accumulator mode not implemented");
900 accum_double->op = accum_op_double_max;
903 accum_double->op = accum_op_double_min;
906 accum_double->op = accum_op_double_plus;
909 accum_double->op = accum_op_double_prod;
912 assert(0 &&
"error: double accumulator operation not implemented");
916 accum_double->open(accum_double, init);
917 return (
accum_t *) accum_double;
923 short accum_get_short(
accum_t * acc) {
925 return acc_short->get(acc_short);
928 void accum_put_short(
accum_t * acc,
short v) {
930 return acc_short->put(acc_short, v);
935 return acc_int->get(acc_int);
940 return acc_int->put(acc_int, v);
943 long accum_get_long(
accum_t * acc) {
945 return acc_long->get(acc_long);
948 void accum_put_long(
accum_t * acc,
long v) {
950 return acc_long->put(acc_long, v);
953 float accum_get_float(
accum_t * acc) {
955 return acc_float->get(acc_float);
958 void accum_put_float(
accum_t * acc,
float v) {
960 return acc_float->put(acc_float, v);
965 return acc_double->get(acc_double);
970 return acc_double->put(acc_double, v);
975 finish_t * finish = get_current_finish();
977 assert((finish->accumulators == NULL) &&
"error: overwritting registered accumulators");
980 accumulators[i] = accs[i];
983 accumulators[i] = NULL;
984 finish->accumulators = accumulators;
989 return acc_impl->destroy(acc_impl);