Commit 69da0ca3 authored by John Zhang's avatar John Zhang
Browse files

modified Mu clock callback to use CCALL of the implementation in C; removed...

modified Mu clock callback to use CCALL of the implementation in C; removed extra parameters passed to cb_begin
parent 8a62c87a
......@@ -20,6 +20,6 @@ This header file defines callback interface for C.
struct Callback; // allow for implementation defined struct
struct Callback* cb_init(const char* param_s);
void cb_begin(struct Callback* cb, void* data); // data is implementation defined
void cb_end(struct Callback* cb, void* data);
void cb_begin(struct Callback* cb); // data is implementation defined
void cb_end(struct Callback* cb);
void cb_report(struct Callback* cb);
......@@ -28,28 +28,28 @@ limitations under the License.
typedef uint64_t timestamp_t;
#include <mach/mach_time.h>
inline void get_nano_timestamp(timestamp_t* tstamp) {
static inline void get_nano_timestamp(timestamp_t* tstamp) {
*tstamp = mach_absolute_time();
}
double get_elapsed_time(timestamp_t t0, timestamp_t t1) {
double get_elapsed_time(timestamp_t* t0, timestamp_t* t1) {
mach_timebase_info_data_t tb;
timestamp_t elapsed;
uint64_t elapsed_nano;
mach_timebase_info(&tb);
elapsed = t1 - t0;
elapsed = *t1 - *t0;
elapsed_nano = elapsed * tb.numer / tb.denom;
return ((double)elapsed_nano) * 1e-9;
}
#else
// Use clock_gettime on Linux
typedef struct timespec timestamp_t;
inline void get_nano_timestamp(timestamp_t* tstamp) {
static inline void get_nano_timestamp(timestamp_t* tstamp) {
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, tstamp);
}
double get_elapsed_time(timestamp_t t0, timestamp_t t1) {
return ((double)(t1.tv_sec - t0.tv_sec)) +
((double)(t1.tv_nsec - t0.tv_nsec)) * 1e-9;
double get_elapsed_time(timestamp_t* t0, timestamp_t* t1) {
return ((double)(t1->tv_sec - t0->tv_sec)) +
((double)(t1->tv_nsec - t0->tv_nsec)) * 1e-9;
}
#endif
......@@ -72,12 +72,12 @@ struct Callback *cb_init(const char *param_s) {
}
// NOTE: assuming current strategy of only one data point per run.
void cb_begin(struct Callback *cb, void *data) {
void cb_begin(struct Callback *cb) {
// call time measurement function
get_nano_timestamp(&cb->t0);
}
void cb_end(struct Callback *cb, void *data) {
void cb_end(struct Callback *cb) {
get_nano_timestamp(&cb->t1);
}
......@@ -85,6 +85,6 @@ void cb_report(struct Callback *cb) {
char fmtstr [6]; // NOTE: assume precision number is at most two digit
sprintf(fmtstr, "%%.%dlf", cb->fltfmtprec);
printf(fmtstr, get_elapsed_time(cb->t0, cb->t1));
printf(fmtstr, get_elapsed_time(&cb->t0, &cb->t1));
printf("\n");
}
......@@ -26,14 +26,14 @@ struct Callback* cb_init(const char* param_s) {
return malloc(sizeof(struct Callback));
}
void cb_begin(struct Callback* cb, void* data) {
void cb_begin(struct Callback* cb) {
printf("begin measurement.\n");
}
void cb_end(struct Callback* cb, void* data) {
void cb_end(struct Callback* cb) {
printf("end measurement.\n");
}
void cb_report(struct Callback* cb) {
print("report.\n");
}
......@@ -21,34 +21,42 @@ void mubench_init_callback_symbols(MuIRBuilder *bldr)
{
// generate symbols
t_callback = bldr->gen_sym(bldr, "@mubench.t_callback");
t_callback_r = bldr->gen_sym(bldr, "@mubench.t_callback_r");
t_logargs = bldr->gen_sym(bldr, "@mubench.t_logargs");
t_logargs_r = bldr->gen_sym(bldr, "@mubench.t_logargs_r");
t_callback_p = bldr->gen_sym(bldr, "@mubench.t_callback_p");
sig_cb_init = bldr->gen_sym(bldr, "@mubench.sig_cb_init");
sig_cb_log = bldr->gen_sym(bldr, "@mubench.sig_cb_log");
sig_cb_begin = bldr->gen_sym(bldr, "@mubench.sig_cb_begin");
sig_cb_end = bldr->gen_sym(bldr, "@mubench.sig_cb_end");
sig_cb_report = bldr->gen_sym(bldr, "@mubench.sig_cb_report");
cb_init = bldr->gen_sym(bldr, "@mubench.cb_init");
cb_begin = bldr->gen_sym(bldr, "@mubench.cb_begin");
cb_end = bldr->gen_sym(bldr, "@mubench.cb_end");
cb_report = bldr->gen_sym(bldr, "@mubench.cb_report");
t_fp_cb_init = bldr->gen_sym(bldr, "@mubench.t_fp_cb_init");
t_fp_cb_begin = bldr->gen_sym(bldr, "@mubench.t_fp_cb_begin");
t_fp_cb_end = bldr->gen_sym(bldr, "@mubench.t_fp_cb_end");
t_fp_cb_report = bldr->gen_sym(bldr, "@mubench.t_fp_cb_report");
extern_cb_init = bldr->gen_sym(bldr, "@mubench.extern_cb_init");
extern_cb_begin = bldr->gen_sym(bldr, "@mubench.extern_cb_begin");
extern_cb_end = bldr->gen_sym(bldr, "@mubench.extern_cb_end");
extern_cb_report = bldr->gen_sym(bldr, "@mubench.extern_cb_report");
t_cchar = bldr->gen_sym(bldr, "@mubench.t_cchar");
t_cchara = bldr->gen_sym(bldr, "@mubench.t_cchara");
t_ccharp = bldr->gen_sym(bldr, "@mubench.t_ccharp");
// define types
bldr->new_type_ref(bldr, t_callback_r, t_callback);
bldr->new_type_ref(bldr, t_logargs_r, t_logargs);
bldr->new_type_uptr(bldr, t_callback_p, t_callback);
bldr->new_funcsig(bldr, sig_cb_init,
(MuTypeNode[1]){t_ccharp}, 1,
(MuTypeNode[1]){t_callback_r}, 1);
bldr->new_funcsig(bldr, sig_cb_log,
(MuTypeNode[2]){t_callback_r, t_logargs_r}, 2, NULL, 0);
(MuTypeNode[1]){t_callback_p}, 1);
bldr->new_funcsig(bldr, sig_cb_begin,
(MuTypeNode[1]){t_callback_p}, 1, NULL, 0);
bldr->new_funcsig(bldr, sig_cb_end,
(MuTypeNode[1]){t_callback_p}, 1, NULL, 0);
bldr->new_funcsig(bldr, sig_cb_report,
(MuTypeNode[1]){t_callback_r}, 1, NULL, 0);
bldr->new_func(bldr, cb_init, sig_cb_init);
bldr->new_func(bldr, cb_begin, sig_cb_log);
bldr->new_func(bldr, cb_end, sig_cb_log);
bldr->new_func(bldr, cb_report, sig_cb_report);
(MuTypeNode[1]){t_callback_p}, 1, NULL, 0);
bldr->new_type_ufuncptr(bldr, t_fp_cb_init, sig_cb_init);
bldr->new_type_ufuncptr(bldr, t_fp_cb_begin, sig_cb_begin);
bldr->new_type_ufuncptr(bldr, t_fp_cb_end, sig_cb_end);
bldr->new_type_ufuncptr(bldr, t_fp_cb_report, sig_cb_report);
bldr->new_const_extern(bldr, extern_cb_init, t_fp_cb_init, "cb_init");
bldr->new_const_extern(bldr, extern_cb_begin, t_fp_cb_begin, "cb_begin");
bldr->new_const_extern(bldr, extern_cb_end, t_fp_cb_end, "cb_end");
bldr->new_const_extern(bldr, extern_cb_report, t_fp_cb_report, "cb_report");
bldr->new_type_int(bldr, t_cchar, 8);
bldr->new_type_hybrid(bldr, t_cchara, NULL, 0, t_cchar);
bldr->new_type_uptr(bldr, t_ccharp, t_cchara);
......
......@@ -31,35 +31,41 @@ extern "C" {
/**
The interface consists of the following definitions:
.type @mubench.t_callback_r = ref<@mubench.t_callback>
.type @mubench.t_logargs_r = ref<@mubench.t_logargs>
.type @mubench.t_callback_p = uptr<@mubench.t_callback>
.type @mubench.t_cchar = int<8>
.type @mubench.t_cchara = hybrid<@mubench.t_cchar>
.type @mubench.t_ccharp = uptr<@mubench.t_cchara>
.funcsig @mubench.sig_cb_init = (@mubench.t_charp) -> (@mubench.t_callback_r)
.funcsig @mubench.sig_cb_log = (@mubench.t_callback_r @mubench.t_logargs_r) -> ()
.funcsig @mubench.sig_cb_report = (@mubench.t_callback_r) -> ()
.funcdecl @mubench.cb_init <@mubench.sig_cb_init>
.funcdecl @mubench.cb_begin <@mubench.sig_cb_log>
.funcdecl @mubench.cb_end <@mubench.sig_cb_log>
.funcdecl @mubench.cb_report <@mubench.sig_cb_report>
.funcsig @mubench.sig_cb_init = (@mubench.t_charp) -> (@mubench.t_callback_p)
.funcsig @mubench.sig_cb_begin = (@mubench.t_callback_p) -> ()
.funcsig @mubench.sig_cb_end = (@mubench.t_callback_p) -> ()
.funcsig @mubench.sig_cb_report = (@mubench.t_callback_p) -> ()
.type @mubench.t_fp_cb_init = ufuncptr<@mubench.sig_cb_init>
.type @mubench.t_fp_cb_begin = ufuncptr<@mubench.sig_cb_begin>
.type @mubench.t_fp_cb_end = ufuncptr<@mubench.sig_cb_end>
.type @mubench.t_fp_cb_report = ufuncptr<@mubench.sig_cb_report>
.const @mubench.extern_cb_init <@mubench.t_fp_cb_init> = EXTERN "cb_init"
.const @mubench.extern_cb_begin <@mubench.t_fp_cb_begin> = EXTERN "cb_begin"
.const @mubench.extern_cb_end <@mubench.t_fp_cb_end> = EXTERN "cb_end"
.const @mubench.extern_cb_report <@mubench.t_fp_cb_report> = EXTERN "cb_report"
relying on subsequent functions to define:
.type @mubench.t_callback
.type @mubench.t_logargs
*/
MuID t_callback;
MuID t_callback_r;
MuID t_logargs;
MuID t_logargs_r;
MuID t_callback_p;
MuID sig_cb_init;
MuID sig_cb_log;
MuID sig_cb_begin;
MuID sig_cb_end;
MuID sig_cb_report;
MuID cb_init;
MuID cb_begin;
MuID cb_end;
MuID cb_report;
MuID t_fp_cb_init;
MuID t_fp_cb_begin;
MuID t_fp_cb_end;
MuID t_fp_cb_report;
MuID extern_cb_init;
MuID extern_cb_begin;
MuID extern_cb_end;
MuID extern_cb_report;
MuID t_cchar;
MuID t_cchara;
MuID t_ccharp;
......
This diff is collapsed.
......@@ -93,10 +93,24 @@ int main(int argc, char **argv)
// get the global definitions and merge them into one array
MuID predef_ids[] = {
t_callback, t_callback_r, t_logargs, t_logargs_r,
sig_cb_init, sig_cb_log, sig_cb_report,
cb_init, cb_begin, cb_end, cb_report,
t_cchar, t_cchara, t_ccharp};
t_callback,
t_callback_p,
sig_cb_init,
sig_cb_begin,
sig_cb_end,
sig_cb_report,
t_fp_cb_init,
t_fp_cb_begin,
t_fp_cb_end,
t_fp_cb_report,
extern_cb_init,
extern_cb_begin,
extern_cb_end,
extern_cb_report,
t_cchar,
t_cchara,
t_ccharp
};
int npredefs = sizeof(predef_ids) / sizeof(MuID);
ngdefs_cb = mubench_get_callback_global_defs(&gdefs_cb);
......
......@@ -33,7 +33,6 @@ limitations under the License.
.const @c_2 <@t_i32> = 2
.const @c_3 <@t_i32> = 3
.const @c_4 <@t_i32> = 4
.const @c_NULL_args <@mubench.t_logargs_r> = NULL
.funcsig @sig_fib = (@t_i32) -> (@t_i32)
.funcsig @sig_main = (@t_i32 @mubench.ccharp) -> (@t_i32)
.funcsig @sig_atoi = (@mubench.ccharp) -> (@t_i32)
......@@ -68,26 +67,26 @@ limitations under the License.
%p_argv_3 = SHIFTIREF PTR <@mubench.ccharp @t_i32> %argv_var @c_3
%argv_3 = LOAD PTR <@mubench.ccharp> %p_argv_3
%cb = CALL <@mubench.sig_cb_init> @mubench.cb_init (%argv_1)
%cb = CCALL <@mubench.t_fp_cb_init @mubench.sig_cb_init> @mubench.extern_cb_init (%argv_1)
%scale_factor = CCALL #DEFAULT <@t_fp_atoi @sig_atoi> @extern_atoi (%argv_2)
%n = CCALL #DEFAULT <@t_fp_atoi @sig_atoi> @extern_atoi (%argv_3)
CALL <@mubench.sig_cb_log> @cb_begin (%cb @c_NULL_args)
CCALL <@mubench.t_fp_cb_begin @mubench.sig_cb_begin> @mubench.extern_cb_begin (%cb)
BRANCH %blk1(@c_0 @c_0 %scale_factor %n %cb)
%blk1(<@t_i32> %i <@t_i32> %sum <@t_i32> %scale_factor <@t_i32> %n <@mubench.t_callback_r> %cb):
%blk1(<@t_i32> %i <@t_i32> %sum <@t_i32> %scale_factor <@t_i32> %n <@mubench.t_callback_p> %cb):
%cmp_res = SLT <@t_i32> %i %scale_factor
BRANCH2 %cmp_res %blk2(%i %sum %scale_factor %n %cb) %blk3(%sum %n %scale_factor %cb)
%blk2(<@t_i32> %i <@t_i32> %sum <@t_i32> %scale_factor <@t_i32> %n <@mubench.t_callback_r> %cb):
%blk2(<@t_i32> %i <@t_i32> %sum <@t_i32> %scale_factor <@t_i32> %n <@mubench.t_callback_p> %cb):
%fib_res = CALL <@sig_fib> @fib (%n)
%sum_inc = ADD <@t_i32> %sum %fib_res
%i_suc = ADD <@t_i32> %i @c_1
BRANCH %blk1(%i_suc %sum_inc %scale_factor %n %cb)
%blk3(<@t_i32> %sum <@t_i32> %n <@t_i32> %scale_factor <@mubench.t_callback_r> %cb):
CALL <@mubench.sig_cb_log> @cb_end (%cb @c_NULL_args)
%blk3(<@t_i32> %sum <@t_i32> %n <@t_i32> %scale_factor <@mubench.t_callback_p> %cb):
CCALL <@mubench.t_fp_cb_end @mubench.sig_cb_end> @mubench.extern_cb_end (%cb)
CALL <@mubench.sig_cb_report> @mubench.cb_report (%cb)
%fib_n = CALL <@sig_fib> @fib (%n)
%expected = MUL <@t_i32> %fib_n %scale_factor
......@@ -98,7 +97,7 @@ limitations under the License.
}
*/
static MuID t_i1, t_i32, t_hccharp, t_ccharpp, t_pccharp, t_fp_atoi, t_fp_exit;
static MuID c_0, c_1, c_2, c_3, c_4, c_NULL_args;
static MuID c_0, c_1, c_2, c_3, c_4;
static MuID sig_fib, sig_main, sig_atoi, sig_exit;
static MuID extern_atoi, extern_exit;
static MuID fib, entry;
......@@ -120,7 +119,6 @@ MuID mubench_build_benchmark(MuIRBuilder *b)
c_2 = b->gen_sym(b, "@c_2");
c_3 = b->gen_sym(b, "@c_3");
c_4 = b->gen_sym(b, "@c_4");
c_NULL_args = b->gen_sym(b, "@c_NULL_args");
sig_fib = b->gen_sym(b, "@sig_fib");
sig_main = b->gen_sym(b, "@sig_main");
sig_atoi = b->gen_sym(b, "@sig_atoi");
......@@ -140,7 +138,6 @@ MuID mubench_build_benchmark(MuIRBuilder *b)
b->new_const_int(b, c_2, t_i32, 2);
b->new_const_int(b, c_3, t_i32, 3);
b->new_const_int(b, c_4, t_i32, 4);
b->new_const_null(b, c_NULL_args, t_logargs_r);
b->new_funcsig(b, sig_fib, IDARR(1, t_i32), 1, IDARR(1, t_i32), 1);
b->new_funcsig(b, sig_main, IDARR(2, t_i32, t_ccharpp), 2, IDARR(1, t_i32), 1);
b->new_funcsig(b, sig_atoi, IDARR(1, t_ccharp), 1, IDARR(1, t_i32), 1);
......@@ -258,8 +255,9 @@ void build_func_entry(MuIRBuilder *b)
b->new_shiftiref(b, ops[5], p_argv_3, true, t_ccharp, t_i32, argv_var, c_3);
b->new_load(b, ops[6], argv_3, true, MU_ORD_NOT_ATOMIC, t_ccharp, p_argv_3, MU_NO_ID);
b->new_call(b, ops[7], IDARR(1, cb), 1, sig_cb_init, cb_init,
IDARR(1, argv_1), 1, MU_NO_ID, MU_NO_ID);
b->new_ccall(b, ops[7], IDARR(1, cb), 1, MU_CC_DEFAULT,
t_fp_cb_init, sig_cb_init, extern_cb_init,
IDARR(1, argv_1), 1, MU_NO_ID, MU_NO_ID);
b->new_ccall(b, ops[8], IDARR(1, scale_factor), 1, MU_CC_DEFAULT,
t_fp_atoi, sig_atoi, extern_atoi,
IDARR(1, argv_2), 1, MU_NO_ID, MU_NO_ID);
......@@ -267,8 +265,9 @@ void build_func_entry(MuIRBuilder *b)
t_fp_atoi, sig_atoi, extern_atoi,
IDARR(1, argv_3), 1, MU_NO_ID, MU_NO_ID);
b->new_call(b, ops[10], NULL, 0, sig_cb_log, cb_begin,
IDARR(2, cb, c_NULL_args), 2, MU_NO_ID, MU_NO_ID);
b->new_ccall(b, ops[10], NULL, 0, MU_CC_DEFAULT,
t_fp_cb_begin, sig_cb_begin, extern_cb_begin,
IDARR(1, cb), 1, MU_NO_ID, MU_NO_ID);
MuID dst = b->gen_sym(b, NULL);
b->new_dest_clause(b, dst, blk1, IDARR(5, c_0, c_0, scale_factor, n, cb), 5);
......@@ -295,7 +294,7 @@ void build_func_entry(MuIRBuilder *b)
b->new_dest_clause(b, if_false, blk3, IDARR(4, sum, n, scale_factor, cb), 4);
b->new_branch2(b, op_br2, cmp_res, if_true, if_false);
b->new_bb(b, blk1, IDARR(5, i, sum, scale_factor, n, cb),
IDARR(5, t_i32, t_i32, t_i32, t_i32, t_callback_r), 5,
IDARR(5, t_i32, t_i32, t_i32, t_i32, t_callback_p), 5,
MU_NO_ID, IDARR(2, op_SLT, op_br2), 2);
}
......@@ -321,7 +320,7 @@ void build_func_entry(MuIRBuilder *b)
b->new_branch(b, ops[3], dst);
b->new_bb(b, blk2,
IDARR(5, i, sum, scale_factor, n, cb),
IDARR(5, t_i32, t_i32, t_i32, t_i32, t_callback_r), 5,
IDARR(5, t_i32, t_i32, t_i32, t_i32, t_callback_p), 5,
MU_NO_ID, ops, 4);
}
......@@ -339,10 +338,12 @@ void build_func_entry(MuIRBuilder *b)
for (int i = 0; i < 8; i ++)
ops[i] = b->gen_sym(b, NULL);
b->new_call(b, ops[0], NULL, 0, sig_cb_log, cb_end,
IDARR(2, cb, c_NULL_args), 2, MU_NO_ID, MU_NO_ID);
b->new_call(b, ops[1], NULL, 0, sig_cb_report, cb_report,
IDARR(1, cb), 1, MU_NO_ID, MU_NO_ID);
b->new_ccall(b, ops[0], NULL, 0, MU_CC_DEFAULT,
t_fp_cb_end, sig_cb_end, extern_cb_end,
IDARR(1, cb), 1, MU_NO_ID, MU_NO_ID);
b->new_ccall(b, ops[1], NULL, 0, MU_CC_DEFAULT,
t_fp_cb_report, sig_cb_report, extern_cb_report,
IDARR(1, cb), 1, MU_NO_ID, MU_NO_ID);
b->new_call(b, ops[2], IDARR(1, fib_n), 1, sig_fib, fib,
IDARR(1, n), 1, MU_NO_ID, MU_NO_ID);
b->new_binop(b, ops[3], expected, MU_BINOP_MUL, t_i32, fib_n, scale_factor, MU_NO_ID);
......@@ -354,7 +355,7 @@ void build_func_entry(MuIRBuilder *b)
b->new_ret(b, ops[7], IDARR(1, c_0), 1);
b->new_bb(b, blk3,
IDARR(4, sum, n, scale_factor, cb),
IDARR(4, t_i32, t_i32, t_i32, t_callback_r), 4,
IDARR(4, t_i32, t_i32, t_i32, t_callback_p), 4,
MU_NO_ID, ops, 8);
}
b->new_func(b, entry, sig_main);
......@@ -377,7 +378,6 @@ int mubench_get_benchmark_global_defs(MuID **parr)
c_2,
c_3,
c_4,
c_NULL_args,
sig_fib,
sig_main,
sig_atoi,
......
Supports Markdown
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