Ejemplo n.º 1
0
channel_range = [0, 1]
f_list.extend([
    Func(fbase, k, k, ch, stride, stride, corefunc, "krnpad")
    for k in kernel_range for ch in channel_range
])

#at last add the generic function that can be used in the else branch in the wrapper.
default_func = Func(fbase, 0, 0, 0, 0, 0, "conv2d_chw", generic=True)
f_list.append(default_func)

#------------------------------------------------------------
# Generate the output file
#------------------------------------------------------------
c = Codegen()
c.set_wrapper_variables({
    'stride_w': "cfg->stride_width",
    'stride_h': "cfg->stride_height"
})
c.set_wrapper_variables({
    'kernel_w': "weights->shape[KRNL_W_DIM_CHW]",
    'kernel_h': "weights->shape[KRNL_H_DIM_CHW]"
})
c.set_wrapper_variables({'channels': "in->shape[FMAP_C_DIM_CHW]"})
c.set_wrapper_variables({'padding_top': "cfg->padding_top"})
c.set_wrapper_variables({'padding_bot': "cfg->padding_bottom"})
c.set_wrapper_variables({'padding_left': "cfg->padding_left"})
c.set_wrapper_variables({'padding_right': "cfg->padding_right"})
c.set_wrapper_hierarchy(
    ['stride_w', 'stride_h', 'kernel_w', 'kernel_h', 'channels', 'padding'])
c.set_wrapper_if_tree(False)

if "fx16" in sys.argv or no_args:
Ejemplo n.º 2
0
ch = 0
f_list.extend([Func(fbase, 1, k, ch, stride, stride, corefunc, "krnpad") for k in kernel_range])
f_list.extend([Func(fbase, k, 1, ch, stride, stride, corefunc, "krnpad") for k in kernel_range])
f_list.extend([Func(fbase, 1, k, ch, stride, stride, corefunc, "nopad") for k in kernel_range])
f_list.extend([Func(fbase, k, 1, ch, stride, stride, corefunc, "nopad") for k in kernel_range])

#at last add the generic function that can be used in the else branch in the wrapper.
corefunc = "avepool_chw_krnpad"
default_func = Func(fbase, 0, 0, 0, 0, 0, corefunc, generic=True)
f_list.append(default_func)

#------------------------------------------------------------
# Generate the output file
#------------------------------------------------------------
c = Codegen()
c.set_wrapper_variables({'stride_w' : "cfg->stride_width", 'stride_h' : "cfg->stride_height"})
c.set_wrapper_variables({'kernel_w' : "cfg->kernel_width", 'kernel_h' : "cfg->kernel_height"})
c.set_wrapper_variables({'padding_top' : "cfg->padding_top"})
c.set_wrapper_variables({'padding_bot' : "cfg->padding_bottom"})
c.set_wrapper_variables({'padding_left' : "cfg->padding_left"})
c.set_wrapper_variables({'padding_right' : "cfg->padding_right"})
c.set_wrapper_hierarchy(['stride_w', 'stride_h', 'kernel_w', 'kernel_h', 'padding'])
c.set_wrapper_if_tree(False)

if "fx16" in sys.argv or no_args:
    f = open(output_file_fx16, "wb")
    f.write(c.print_file(f_list, default_func, func_body_template_file, file_template, include_list, define_list))
    f.close()

#------------------------------------------------------------
# Create a new list of specialization functions for fx8