提交 403e8110 编写于 作者: L lvwenyuan 00536823

add env var to control whether dump gpu ir and cuda

上级 a8faeda6
...@@ -176,7 +176,8 @@ def build_cuda(outputs, args, sch_name, kernel_name): ...@@ -176,7 +176,8 @@ def build_cuda(outputs, args, sch_name, kernel_name):
} }
with tvm.target.cuda() as cuda: with tvm.target.cuda() as cuda:
s = scheduler[sch_name](outputs) s = scheduler[sch_name](outputs)
with tvm.build_config(dump_pass_ir = True): dump_ir = os.getenv('MS_AKG_DUMP_IR') == "on"
with tvm.build_config(dump_pass_ir = dump_ir):
mod = tvm.build(s, args, cuda, name = kernel_name) mod = tvm.build(s, args, cuda, name = kernel_name)
dump_cuda_meta.dump(mod, kernel_name, s, list(args)) dump_cuda_meta.dump(mod, kernel_name, s, list(args))
return mod return mod
...@@ -82,7 +82,10 @@ def compilewithjson_to_func(json_str): ...@@ -82,7 +82,10 @@ def compilewithjson_to_func(json_str):
if kernel_info['attr']: if kernel_info['attr']:
for ext_arg in kernel_info['attr']: for ext_arg in kernel_info['attr']:
op_attrs.append(ext_arg['value']) op_attrs.append(ext_arg['value'])
mod = utils.op_build(op_func, input_shapes, input_types, op_attrs, kernel_info['op']) dump_ir = os.getenv('MS_AKG_DUMP_IR') == "on"
dump_code = os.getenv('MS_AKG_DUMP_CODE') == "on"
mod = utils.op_build(op_func, input_shapes, input_types, op_attrs, kernel_info['op'], dump_ir=dump_ir,
dump_code=dump_code)
return True return True
else: else:
op_func = getattr(cce, op_name, None) op_func = getattr(cce, op_name, None)
......
...@@ -31,7 +31,7 @@ from akg.utils import validation_check as vc_util ...@@ -31,7 +31,7 @@ from akg.utils import validation_check as vc_util
BINDS = "binds" BINDS = "binds"
MS_AKG_DUMP_IR = "MS_AKG_DUMP_IR" MS_AKG_DUMP_IR = "MS_AKG_DUMP_IR"
MS_AKG_DUMP_CCE = "MS_AKG_DUMP_CCE" MS_AKG_DUMP_CODE = "MS_AKG_DUMP_CODE"
MS_DAVINCI_KERNEL_PATH = "./kernel_meta/" MS_DAVINCI_KERNEL_PATH = "./kernel_meta/"
......
...@@ -294,7 +294,7 @@ def maxpool_manual_schedule(shape, kernel, stride, padding, dtype, attrs=None, p ...@@ -294,7 +294,7 @@ def maxpool_manual_schedule(shape, kernel, stride, padding, dtype, attrs=None, p
mod = akg.build(s, [data, res], "cce", name="maxpool_manual_schedule", attrs=attrs, polyhedral=polyhedral) mod = akg.build(s, [data, res], "cce", name="maxpool_manual_schedule", attrs=attrs, polyhedral=polyhedral)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
kernel_name = "maxpool_ad_manual_schedule" kernel_name = "maxpool_ad_manual_schedule"
utils.create_cce(kernel_name, './', source_code) utils.create_code(kernel_name, './', source_code)
return mod return mod
def pad_strategy_check(strategy): def pad_strategy_check(strategy):
......
...@@ -387,7 +387,7 @@ def maxpool_ad_manual_schedule_all_max(shape, kernel, stride, pad, dtype, polyhe ...@@ -387,7 +387,7 @@ def maxpool_ad_manual_schedule_all_max(shape, kernel, stride, pad, dtype, polyhe
attrs=attrs, polyhedral=polyhedral) attrs=attrs, polyhedral=polyhedral)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
kernel_name = "maxpool_ad_manual_schedule_all_max" kernel_name = "maxpool_ad_manual_schedule_all_max"
utils.create_cce(kernel_name, './', source_code) utils.create_code(kernel_name, './', source_code)
return mod return mod
...@@ -489,5 +489,5 @@ def maxpool_ad_manual_schedule_no_overlap_all_max(shape, kernel, stride, pad, dt ...@@ -489,5 +489,5 @@ def maxpool_ad_manual_schedule_no_overlap_all_max(shape, kernel, stride, pad, dt
name="maxpool_ad_manual_schedule_no_overlap_all_max", attrs=attrs, polyhedral=polyhedral) name="maxpool_ad_manual_schedule_no_overlap_all_max", attrs=attrs, polyhedral=polyhedral)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
kernel_name = "maxpool_ad_manual_schedule_no_overlap_all_max" kernel_name = "maxpool_ad_manual_schedule_no_overlap_all_max"
utils.create_cce(kernel_name, './', source_code) utils.create_code(kernel_name, './', source_code)
return mod return mod
...@@ -64,6 +64,18 @@ def save_gpu_params(s, args, kernel_info): ...@@ -64,6 +64,18 @@ def save_gpu_params(s, args, kernel_info):
ptx_code = kernel_info[0] ptx_code = kernel_info[0]
file_name = kernel_info[1] file_name = kernel_info[1]
kernel_name = kernel_info[2] kernel_name = kernel_info[2]
dump_ir = os.getenv('MS_AKG_DUMP_IR') == "on"
if dump_ir:
schedule_path = os.path.realpath(kernel_name)
all_passes = os.listdir(schedule_path)
for cur_pass in all_passes:
if cur_pass.startswith("00_"):
with open(schedule_path + '/' + cur_pass, "r") as file:
ir = file.read()
break
else:
ir = str(akg.tvm.lower(s, args, simple_mode=True)) ir = str(akg.tvm.lower(s, args, simple_mode=True))
file_path = os.path.realpath(file_name) file_path = os.path.realpath(file_name)
if os.path.exists(file_path): if os.path.exists(file_path):
......
...@@ -67,23 +67,35 @@ def func_time_required(func_name): ...@@ -67,23 +67,35 @@ def func_time_required(func_name):
return wrapper return wrapper
def create_cce(kernel_name, cce_path=None, code=None): def create_code(kernel_name, code_path=None, code=None, code_type="CCE"):
""" """
Create cce file. Create cce or cuda file.
Args: Args:
kernel_name: cce file name. kernel_name: file name.
cce_path: cce file path. code_path: file path.
code: cce code. code: code.
code_type: code type.
""" """
if cce_path: if code_type == "CCE":
if len(cce_path) > 4 and cce_path[-4:].lower() == ".cce": postfix = ".cce"
real_path = cce_path elif code_type == "CUDA":
postfix = ".cu"
else: else:
if cce_path[-1] == r"/": logging.info("the target code type %s is not supported.", code_type)
real_path = cce_path + kernel_name + ".cce"
if not code_path:
code_path = "./"
if code_type == "CCE" and len(code_path) > 4 and code_path[-4:].lower() == postfix:
real_path = code_path
elif code_type == "CUDA" and len(code_path) > 3 and code_path[-3:].lower() == postfix:
real_path = code_path
else:
if code_path[-1] == r"/":
real_path = code_path + kernel_name + postfix
else: else:
real_path = cce_path + r"/" + kernel_name + ".cce" real_path = code_path + r"/" + kernel_name + postfix
dir_path = r"/".join(real_path.split(r"/")[:-1]) dir_path = r"/".join(real_path.split(r"/")[:-1])
if not os.path.isdir(dir_path): if not os.path.isdir(dir_path):
os.makedirs(dir_path) os.makedirs(dir_path)
...@@ -92,6 +104,7 @@ def create_cce(kernel_name, cce_path=None, code=None): ...@@ -92,6 +104,7 @@ def create_cce(kernel_name, cce_path=None, code=None):
ss.write(code) ss.write(code)
def gen_name_kernel(kernel, dtype, shapes): def gen_name_kernel(kernel, dtype, shapes):
"""generate kernel name.""" """generate kernel name."""
def _flat_array(srclist, dstlist): def _flat_array(srclist, dstlist):
...@@ -538,7 +551,7 @@ def gen_kernel_name(input_shapes, input_types, op_attrs=None, kernel_name=""): ...@@ -538,7 +551,7 @@ def gen_kernel_name(input_shapes, input_types, op_attrs=None, kernel_name=""):
@func_time_required @func_time_required
def op_build_test(op_func, input_shapes, input_types, op_attrs=None, kernel_name="", def op_build_test(op_func, input_shapes, input_types, op_attrs=None, kernel_name="",
attrs=None, log_cce=False, dump_ir=True, dump_cce=True, attrs=None, log_cce=False, dump_ir=True, dump_code=True,
polyhedral=True, tuning=False): polyhedral=True, tuning=False):
""" """
Return module from op_build with given inputs, distinguish tuning mode. Return module from op_build with given inputs, distinguish tuning mode.
...@@ -552,7 +565,7 @@ def op_build_test(op_func, input_shapes, input_types, op_attrs=None, kernel_name ...@@ -552,7 +565,7 @@ def op_build_test(op_func, input_shapes, input_types, op_attrs=None, kernel_name
attrs (dict): tiling parameter. attrs (dict): tiling parameter.
log_cce (bool): False by default. log_cce (bool): False by default.
dump_ir (bool): True by default. dump_ir (bool): True by default.
dump_cce (bool): False by default. dump_code (bool): False by default.
polyhedral (bool): True by default. polyhedral (bool): True by default.
tuning (bool): False by default. tuning (bool): False by default.
...@@ -565,7 +578,7 @@ def op_build_test(op_func, input_shapes, input_types, op_attrs=None, kernel_name ...@@ -565,7 +578,7 @@ def op_build_test(op_func, input_shapes, input_types, op_attrs=None, kernel_name
kernel_name = gen_kernel_name(input_shapes, input_types, op_attrs, kernel_name) kernel_name = gen_kernel_name(input_shapes, input_types, op_attrs, kernel_name)
logging.debug('kernel_name---------- %s', str(kernel_name)) logging.debug('kernel_name---------- %s', str(kernel_name))
mod = op_build(op_func, input_shapes, input_types, op_attrs, kernel_name, mod = op_build(op_func, input_shapes, input_types, op_attrs, kernel_name,
attrs, log_cce, dump_ir, dump_cce, attrs, log_cce, dump_ir, dump_code,
polyhedral, tuning) polyhedral, tuning)
return mod return mod
...@@ -593,7 +606,7 @@ def recursive_copy(obj): ...@@ -593,7 +606,7 @@ def recursive_copy(obj):
def op_build(op_func, input_shapes, input_types, op_attrs=None, kernel_name="", def op_build(op_func, input_shapes, input_types, op_attrs=None, kernel_name="",
attrs=None, log_cce=False, dump_ir=True, dump_cce=True, attrs=None, log_cce=False, dump_ir=True, dump_code=True,
polyhedral=True, tuning=False): polyhedral=True, tuning=False):
""" """
Return module built from op_func with given inputs. Return module built from op_func with given inputs.
...@@ -607,7 +620,7 @@ def op_build(op_func, input_shapes, input_types, op_attrs=None, kernel_name="", ...@@ -607,7 +620,7 @@ def op_build(op_func, input_shapes, input_types, op_attrs=None, kernel_name="",
attrs (dict): tiling parameter. attrs (dict): tiling parameter.
log_cce (bool): False by default. log_cce (bool): False by default.
dump_ir (bool): True by default. dump_ir (bool): True by default.
dump_cce (bool): False by default. dump_code (bool): False by default.
polyhedral (bool): True by default. polyhedral (bool): True by default.
tuning (bool): False by default. tuning (bool): False by default.
...@@ -730,9 +743,13 @@ def op_build(op_func, input_shapes, input_types, op_attrs=None, kernel_name="", ...@@ -730,9 +743,13 @@ def op_build(op_func, input_shapes, input_types, op_attrs=None, kernel_name="",
kernel_name = kernel_name if kernel_name != "" else sch_tmpl['op_name'] kernel_name = kernel_name if kernel_name != "" else sch_tmpl['op_name']
with akg.tvm.target.cuda() as target: with akg.tvm.target.cuda() as target:
s = sch_tmpl['schedule'](sch_tmpl['output']) s = sch_tmpl['schedule'](sch_tmpl['output'])
with akg.build_config(dump_pass_ir=True): with akg.tvm.build_config(dump_pass_ir=dump_ir):
mod = akg.build(s, op_var, "cuda", shape_var, name=kernel_name, attrs=attrs, polyhedral=polyhedral, binds=binds) mod = akg.build(s, op_var, "cuda", shape_var, name=kernel_name, attrs=attrs,
polyhedral=polyhedral, binds=binds)
dump_cuda_meta.dump(mod, kernel_name, s, op_var) dump_cuda_meta.dump(mod, kernel_name, s, op_var)
if dump_code:
source_code = mod.imported_modules[0].get_source()
create_code(kernel_name, "./", source_code, "CUDA")
return mod return mod
if isinstance(output, (list, tuple)): if isinstance(output, (list, tuple)):
...@@ -781,9 +798,9 @@ def op_build(op_func, input_shapes, input_types, op_attrs=None, kernel_name="", ...@@ -781,9 +798,9 @@ def op_build(op_func, input_shapes, input_types, op_attrs=None, kernel_name="",
if log_cce: if log_cce:
logging.debug("#################cce code####################") logging.debug("#################cce code####################")
logging.debug(source_code) logging.debug(source_code)
if dump_cce: if dump_code:
cce_path = "./" code_path = "./"
create_cce(kernel_name, cce_path, source_code) create_code(kernel_name, code_path, source_code)
return mod return mod
......
...@@ -1110,8 +1110,8 @@ air::runtime::Module BuildToModule(const NodeRef &ref, const std::string &target ...@@ -1110,8 +1110,8 @@ air::runtime::Module BuildToModule(const NodeRef &ref, const std::string &target
mhost.Import(mdev); mhost.Import(mdev);
} }
const char *akg_dump_cce = getenv("MS_AKG_DUMP_CCE"); const char *akg_dump_code = getenv("MS_AKG_DUMP_CODE");
if (akg_dump_cce != nullptr) { if (akg_dump_code != nullptr) {
auto mod0 = mhost->imports()[0]; auto mod0 = mhost->imports()[0];
CHECK(mod0.defined()); CHECK(mod0.defined());
......
...@@ -207,7 +207,7 @@ def add_a_conv(fmap_shape, filter_shape, pad_, stride_, dilation_, ...@@ -207,7 +207,7 @@ def add_a_conv(fmap_shape, filter_shape, pad_, stride_, dilation_,
mod = akg.build(s, [a_value, b_value, conv], "cce", name=kernel_name, attrs=attrs, polyhedral=True) mod = akg.build(s, [a_value, b_value, conv], "cce", name=kernel_name, attrs=attrs, polyhedral=True)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
cce_path = '.' cce_path = '.'
utils.create_cce(kernel_name, cce_path, source_code) utils.create_code(kernel_name, cce_path, source_code)
return mod return mod
......
...@@ -201,7 +201,7 @@ def add_b_conv(fmap_shape, filter_shape, pad_, stride_, dilation_, ...@@ -201,7 +201,7 @@ def add_b_conv(fmap_shape, filter_shape, pad_, stride_, dilation_,
mod = akg.build(s, [a_value, b_value, conv], "cce", name=kernel_name, attrs=attrs, polyhedral=True) mod = akg.build(s, [a_value, b_value, conv], "cce", name=kernel_name, attrs=attrs, polyhedral=True)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
cce_path = '.' cce_path = '.'
utils.create_cce(kernel_name, cce_path, source_code) utils.create_code(kernel_name, cce_path, source_code)
return mod return mod
......
...@@ -64,5 +64,5 @@ def col2im_manual_schedule(shape, kernel, stride, pad, dtype, output_H_W, polyhe ...@@ -64,5 +64,5 @@ def col2im_manual_schedule(shape, kernel, stride, pad, dtype, output_H_W, polyhe
mod = akg.build(s, [data, res], "cce", name="col2im_manual_schedule", attrs=attrs, polyhedral=polyhedral) mod = akg.build(s, [data, res], "cce", name="col2im_manual_schedule", attrs=attrs, polyhedral=polyhedral)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
kernel_name = "col2im_manual_schedule" kernel_name = "col2im_manual_schedule"
utils.create_cce(kernel_name, "./", source_code) utils.create_code(kernel_name, "./", source_code)
return mod return mod
...@@ -115,6 +115,6 @@ def gather(params_shape, indices_shape, params_dtype, indices_dtype, axis, kerne ...@@ -115,6 +115,6 @@ def gather(params_shape, indices_shape, params_dtype, indices_dtype, axis, kerne
mod = akg.build(s, [xx, yy, res], "cce", name=kernel_name, attrs=attrs) mod = akg.build(s, [xx, yy, res], "cce", name=kernel_name, attrs=attrs)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
utils.create_cce(kernel_name, cce_path, source_code) utils.create_code(kernel_name, cce_path, source_code)
return mod return mod
...@@ -109,5 +109,5 @@ def im2col_manual_schedule(shape, kernel, stride, pad, dtype, polyhedral=True, a ...@@ -109,5 +109,5 @@ def im2col_manual_schedule(shape, kernel, stride, pad, dtype, polyhedral=True, a
attrs=attrs, polyhedral=polyhedral) attrs=attrs, polyhedral=polyhedral)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
kernel_name = "im2col_manual_schedule" kernel_name = "im2col_manual_schedule"
utils.create_cce(kernel_name, './', source_code) utils.create_code(kernel_name, './', source_code)
return mod return mod
...@@ -200,5 +200,5 @@ def reduce_max_ad_optimized_manual_schedule(input_shape, dtype, axis, keepdims, ...@@ -200,5 +200,5 @@ def reduce_max_ad_optimized_manual_schedule(input_shape, dtype, axis, keepdims,
name="reduce_max_ad_manual_schedule", attrs=attrs, polyhedral=polyhedral) name="reduce_max_ad_manual_schedule", attrs=attrs, polyhedral=polyhedral)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
kernel_name = "reduce_max_ad_manual_schedule" kernel_name = "reduce_max_ad_manual_schedule"
utils.create_cce(kernel_name, './', source_code) utils.create_code(kernel_name, './', source_code)
return mod return mod
...@@ -159,5 +159,5 @@ def reduce_min_ad_optimized_manual_schedule(input_shape, dtype, axis, keepdims, ...@@ -159,5 +159,5 @@ def reduce_min_ad_optimized_manual_schedule(input_shape, dtype, axis, keepdims,
attrs=attrs, polyhedral=polyhedral) attrs=attrs, polyhedral=polyhedral)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
kernel_name = "reduce_min_ad_manual_schedule" kernel_name = "reduce_min_ad_manual_schedule"
utils.create_cce(kernel_name, './', source_code) utils.create_code(kernel_name, './', source_code)
return mod return mod
...@@ -105,5 +105,5 @@ def vector_matmul(data_m, data_n, data_k, trans_a, trans_b, dtype, kernel_name, ...@@ -105,5 +105,5 @@ def vector_matmul(data_m, data_n, data_k, trans_a, trans_b, dtype, kernel_name,
with akg.build_config(add_lower_pass=cce.debug_mode(0), dump_pass_ir=True): with akg.build_config(add_lower_pass=cce.debug_mode(0), dump_pass_ir=True):
mod = akg.build(forward_s, op_vars, "cce", name=kernel_name, attrs=attrs, polyhedral=True) mod = akg.build(forward_s, op_vars, "cce", name=kernel_name, attrs=attrs, polyhedral=True)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
utils.create_cce(kernel_name, "./", source_code) utils.create_code(kernel_name, "./", source_code)
return mod, output_shape return mod, output_shape
...@@ -81,7 +81,7 @@ def iou_for_train_run(shape_tensor, ...@@ -81,7 +81,7 @@ def iou_for_train_run(shape_tensor,
output = utils.mod_launch(mod, (anchor, ground_truth, output), expect=expect) output = utils.mod_launch(mod, (anchor, ground_truth, output), expect=expect)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
utils.create_cce(kernel_name, "./", source_code) utils.create_code(kernel_name, "./", source_code)
return input, output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True) return input, output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True)
......
...@@ -41,7 +41,7 @@ def avgpool_ad_run(shape, kernel, stride, pad, dtype, polyhedral=False, attrs=No ...@@ -41,7 +41,7 @@ def avgpool_ad_run(shape, kernel, stride, pad, dtype, polyhedral=False, attrs=No
input = random_gaussian(shape, miu=1, sigma=0.1).astype(support_list[dtype]) input = random_gaussian(shape, miu=1, sigma=0.1).astype(support_list[dtype])
y = avgpool_run.benchmark(input, kernel, stride, pad) y = avgpool_run.benchmark(input, kernel, stride, pad)
mod = utils.op_build_test(avgpool, [y.shape, shape], [dtype, dtype], op_attrs=[kernel, stride, pad], mod = utils.op_build_test(avgpool, [y.shape, shape], [dtype, dtype], op_attrs=[kernel, stride, pad],
kernel_name=kernel_name, attrs=attrs, log_cce=True, dump_cce=True, tuning=t) kernel_name=kernel_name, attrs=attrs, log_cce=True, dump_code=True, tuning=t)
if t: if t:
expect, head, output = gen_data(dtype, input, kernel, pad, stride, support_list, y) expect, head, output = gen_data(dtype, input, kernel, pad, stride, support_list, y)
return mod, expect, (head, input, output) return mod, expect, (head, input, output)
...@@ -51,7 +51,7 @@ def avgpool_ad_run(shape, kernel, stride, pad, dtype, polyhedral=False, attrs=No ...@@ -51,7 +51,7 @@ def avgpool_ad_run(shape, kernel, stride, pad, dtype, polyhedral=False, attrs=No
input = random_gaussian(shape, miu=1, sigma=0.1).astype(support_list[dtype]) input = random_gaussian(shape, miu=1, sigma=0.1).astype(support_list[dtype])
y = avgpool_run.benchmark(input, kernel, stride, pad) y = avgpool_run.benchmark(input, kernel, stride, pad)
mod = utils.op_build_test(avgpool, [y.shape, shape], [dtype, dtype], op_attrs=[kernel, stride, pad], mod = utils.op_build_test(avgpool, [y.shape, shape], [dtype, dtype], op_attrs=[kernel, stride, pad],
kernel_name=kernel_name, attrs=attrs, log_cce=True, dump_cce=True) kernel_name=kernel_name, attrs=attrs, log_cce=True, dump_code=True)
expect, head, output = gen_data(dtype, input, kernel, pad, stride, support_list, y) expect, head, output = gen_data(dtype, input, kernel, pad, stride, support_list, y)
output = utils.mod_launch(mod, [head, input, output], expect=expect) output = utils.mod_launch(mod, [head, input, output], expect=expect)
......
...@@ -197,7 +197,7 @@ def bounding_box_encode_run(anchor_box_shape, groundtruth_box_shape, anchor_samp ...@@ -197,7 +197,7 @@ def bounding_box_encode_run(anchor_box_shape, groundtruth_box_shape, anchor_samp
mod = utils.op_build_test(bounding_box_encode.bouding_box_encode, mod = utils.op_build_test(bounding_box_encode.bouding_box_encode,
[anchor_box_shape, groundtruth_box_shape, anchor_samples_shape], [anchor_box_shape, groundtruth_box_shape, anchor_samples_shape],
[dtype, dtype, "int32"], [dtype, dtype, "int32"],
op_attrs, kernel_name=kernel_name, attrs=attrs, dump_cce=True, tuning=t) op_attrs, kernel_name=kernel_name, attrs=attrs, dump_code=True, tuning=t)
if t: if t:
anchor_box_data, anchor_samples_data, expect, groundtruth_box_data, output_data = gen_data(anchor_box_shape, anchor_box_data, anchor_samples_data, expect, groundtruth_box_data, output_data = gen_data(anchor_box_shape,
anchor_samples_shape, anchor_samples_shape,
...@@ -211,7 +211,7 @@ def bounding_box_encode_run(anchor_box_shape, groundtruth_box_shape, anchor_samp ...@@ -211,7 +211,7 @@ def bounding_box_encode_run(anchor_box_shape, groundtruth_box_shape, anchor_samp
mod = utils.op_build_test(bounding_box_encode.bouding_box_encode, mod = utils.op_build_test(bounding_box_encode.bouding_box_encode,
[anchor_box_shape, groundtruth_box_shape, anchor_samples_shape], [anchor_box_shape, groundtruth_box_shape, anchor_samples_shape],
[dtype, dtype, "int32"], [dtype, dtype, "int32"],
op_attrs, kernel_name=kernel_name, attrs=attrs, dump_cce=True) op_attrs, kernel_name=kernel_name, attrs=attrs, dump_code=True)
anchor_box_data, anchor_samples_data, expect, groundtruth_box_data, output_data = gen_data(anchor_box_shape, anchor_box_data, anchor_samples_data, expect, groundtruth_box_data, output_data = gen_data(anchor_box_shape,
anchor_samples_shape, anchor_samples_shape,
dtype, epsilon, dtype, epsilon,
......
...@@ -192,7 +192,7 @@ def conv_filter_ad_run(fmap_shape, filter_shape, pad_, stride_, dilation_, attr ...@@ -192,7 +192,7 @@ def conv_filter_ad_run(fmap_shape, filter_shape, pad_, stride_, dilation_, attr
return np_input, out_data, expect, True return np_input, out_data, expect, True
mod = utils.op_build_test(conv_filter_ad.conv_filter_ad, [dw_input_shapes], [conv_dtype], mod = utils.op_build_test(conv_filter_ad.conv_filter_ad, [dw_input_shapes], [conv_dtype],
op_attrs=[fmap_shape, filter_shape, pad_, stride_, dilation_], kernel_name='conv_filter_ad', attrs=attrs, dump_cce = True) op_attrs=[fmap_shape, filter_shape, pad_, stride_, dilation_], kernel_name='conv_filter_ad', attrs=attrs, dump_code = True)
args = (dy_data, dx_data, out_data) args = (dy_data, dx_data, out_data)
out_data = utils.mod_launch(mod, args, expect=expect) out_data = utils.mod_launch(mod, args, expect=expect)
rtol, atol = get_rtol_atol("conv_filter_ad", conv_dtype) rtol, atol = get_rtol_atol("conv_filter_ad", conv_dtype)
......
...@@ -34,7 +34,7 @@ def conv_run_mansch(FMap_shape, Filter_shape, Pad, Stride, Dilation=None, use_bi ...@@ -34,7 +34,7 @@ def conv_run_mansch(FMap_shape, Filter_shape, Pad, Stride, Dilation=None, use_bi
use_bias=use_bias, fp32_mad=fp32_mad, kernel_name="conv_mansch") use_bias=use_bias, fp32_mad=fp32_mad, kernel_name="conv_mansch")
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
utils.create_cce("conv_mansch", ".", source_code) utils.create_code("conv_mansch", ".", source_code)
A, B, bias_data, expect = gen_data(FMap_shape, Filter_shape, Pad, Stride, Dilation, use_bias) A, B, bias_data, expect = gen_data(FMap_shape, Filter_shape, Pad, Stride, Dilation, use_bias)
expect = expect.reshape((expect.shape[0], expect.shape[1], expect.shape[2]*expect.shape[3],expect.shape[4])) # output on conv2d is in 4d format expect = expect.reshape((expect.shape[0], expect.shape[1], expect.shape[2]*expect.shape[3],expect.shape[4])) # output on conv2d is in 4d format
......
...@@ -26,7 +26,7 @@ def logprob_ad_run(shape, dtype, kernel_name="", attrs=None): ...@@ -26,7 +26,7 @@ def logprob_ad_run(shape, dtype, kernel_name="", attrs=None):
mod = utils.op_build_test(distr_bernoulli_logprob_ad.bernoulli_logprob_ad, [head.shape, x.shape, probs.shape], mod = utils.op_build_test(distr_bernoulli_logprob_ad.bernoulli_logprob_ad, [head.shape, x.shape, probs.shape],
[dtype, dtype, dtype], kernel_name=kernel_name, [dtype, dtype, dtype], kernel_name=kernel_name,
op_attrs=None, attrs=None, log_cce=True, dump_cce=True, polyhedral=True) op_attrs=None, attrs=None, log_cce=True, dump_code=True, polyhedral=True)
outputs = utils.mod_launch(mod, [head, x, probs, *outputs], outputs=tuple(range(-len(outputs), 0)), expect=expects) outputs = utils.mod_launch(mod, [head, x, probs, *outputs], outputs=tuple(range(-len(outputs), 0)), expect=expects)
outputs = list(outputs) outputs = list(outputs)
......
...@@ -29,7 +29,7 @@ def log_prob_run(shape, dtype, kernelname="", attrs = None): ...@@ -29,7 +29,7 @@ def log_prob_run(shape, dtype, kernelname="", attrs = None):
mod = utils.op_build_test(log_prob_op, [x.shape, probs.shape], mod = utils.op_build_test(log_prob_op, [x.shape, probs.shape],
[dtype, dtype], kernel_name=kernelname, [dtype, dtype], kernel_name=kernelname,
op_attrs=[], attrs=None, log_cce=True, dump_cce=True, polyhedral=True) op_attrs=[], attrs=None, log_cce=True, dump_code=True, polyhedral=True)
output = utils.mod_launch(mod, [x, probs, output], expect=expect) output = utils.mod_launch(mod, [x, probs, output], expect=expect)
return (x, probs), output, expect, compare_tensor(output, expect, rtol=1e-03, atol=1e-03, equal_nan=True) return (x, probs), output, expect, compare_tensor(output, expect, rtol=1e-03, atol=1e-03, equal_nan=True)
......
...@@ -25,7 +25,7 @@ def KLdiv_ad_run(shape, dtype, kernel_name="", attrs=None): ...@@ -25,7 +25,7 @@ def KLdiv_ad_run(shape, dtype, kernel_name="", attrs=None):
mod = utils.op_build_test(distr_normal_diag_KLdiv_ad.normal_diag_KLdiv_ad, [head.shape, mean.shape, scale.shape], mod = utils.op_build_test(distr_normal_diag_KLdiv_ad.normal_diag_KLdiv_ad, [head.shape, mean.shape, scale.shape],
[dtype, dtype, dtype], kernel_name=kernel_name, [dtype, dtype, dtype], kernel_name=kernel_name,
op_attrs=None, attrs=None, log_cce=True, dump_cce=True, polyhedral=True) op_attrs=None, attrs=None, log_cce=True, dump_code=True, polyhedral=True)
outputs = utils.mod_launch(mod, [head, mean, scale, *outputs], outputs=tuple(range(-len(outputs), 0)), expect=expects) outputs = utils.mod_launch(mod, [head, mean, scale, *outputs], outputs=tuple(range(-len(outputs), 0)), expect=expects)
outputs = list(outputs) outputs = list(outputs)
......
...@@ -27,7 +27,7 @@ def KLdiv_run(shape, dtype, kernelname="", attrs = None): ...@@ -27,7 +27,7 @@ def KLdiv_run(shape, dtype, kernelname="", attrs = None):
mod = utils.op_build_test(KLdiv_op, [mean.shape, scale.shape], mod = utils.op_build_test(KLdiv_op, [mean.shape, scale.shape],
[dtype, dtype], kernel_name=kernelname, [dtype, dtype], kernel_name=kernelname,
op_attrs=[], attrs=None, log_cce=True, dump_cce=True, polyhedral=True) op_attrs=[], attrs=None, log_cce=True, dump_code=True, polyhedral=True)
output = utils.mod_launch(mod, [mean, scale, output], expect = expect) output = utils.mod_launch(mod, [mean, scale, output], expect = expect)
return (mean, scale), output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True) return (mean, scale), output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True)
......
...@@ -30,7 +30,7 @@ def logprob_ad_run(shape, dtype, kernel_name="", attrs=None): ...@@ -30,7 +30,7 @@ def logprob_ad_run(shape, dtype, kernel_name="", attrs=None):
op_attrs=None, op_attrs=None,
attrs=None, attrs=None,
log_cce=True, log_cce=True,
dump_cce=True, dump_code=True,
polyhedral=True, polyhedral=True,
) )
outputs = utils.mod_launch( outputs = utils.mod_launch(
......
...@@ -28,7 +28,7 @@ def logprob_run(shape, dtype, kernelname="", attrs = None): ...@@ -28,7 +28,7 @@ def logprob_run(shape, dtype, kernelname="", attrs = None):
mod = utils.op_build_test(logprob_op, [x.shape, mean.shape, scale.shape], mod = utils.op_build_test(logprob_op, [x.shape, mean.shape, scale.shape],
[dtype, dtype, dtype], kernel_name=kernelname, [dtype, dtype, dtype], kernel_name=kernelname,
op_attrs=[], attrs=None, log_cce=True, dump_cce=True, polyhedral=True) op_attrs=[], attrs=None, log_cce=True, dump_code=True, polyhedral=True)
output = utils.mod_launch(mod, [x, mean, scale, output], expect = expect) output = utils.mod_launch(mod, [x, mean, scale, output], expect = expect)
return (x, mean, scale), output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True) return (x, mean, scale), output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True)
......
...@@ -24,7 +24,7 @@ def sample_ad_run(shape, dtype, kernel_name="", attrs=None): ...@@ -24,7 +24,7 @@ def sample_ad_run(shape, dtype, kernel_name="", attrs=None):
mod = utils.op_build_test(distr_normal_diag_sample_ad.normal_diag_sample_ad, [head.shape, mean.shape, scale.shape, eps.shape], mod = utils.op_build_test(distr_normal_diag_sample_ad.normal_diag_sample_ad, [head.shape, mean.shape, scale.shape, eps.shape],
[dtype, dtype, dtype, dtype], kernel_name=kernel_name, [dtype, dtype, dtype, dtype], kernel_name=kernel_name,
op_attrs=None, attrs=None, log_cce=True, dump_cce=True, polyhedral=True) op_attrs=None, attrs=None, log_cce=True, dump_code=True, polyhedral=True)
outputs = utils.mod_launch(mod, [head, mean, scale, eps, *outputs], outputs=tuple(range(-len(outputs), 0)), expect=expects) outputs = utils.mod_launch(mod, [head, mean, scale, eps, *outputs], outputs=tuple(range(-len(outputs), 0)), expect=expects)
outputs = list(outputs) outputs = list(outputs)
......
...@@ -26,7 +26,7 @@ def sample_run(shape, dtype, kernel_name="", attrs=None): ...@@ -26,7 +26,7 @@ def sample_run(shape, dtype, kernel_name="", attrs=None):
mod = utils.op_build_test(sample_op, [mean.shape, scale.shape, eps.shape], mod = utils.op_build_test(sample_op, [mean.shape, scale.shape, eps.shape],
[dtype, dtype, dtype], kernel_name=kernel_name, [dtype, dtype, dtype], kernel_name=kernel_name,
op_attrs=None, attrs=None, log_cce=True, dump_cce=True, polyhedral=True) op_attrs=None, attrs=None, log_cce=True, dump_code=True, polyhedral=True)
output = utils.mod_launch(mod, [mean, scale, eps, output], expect=expect) output = utils.mod_launch(mod, [mean, scale, eps, output], expect=expect)
return (mean, scale, eps), output, expect, compare_tensor(output, expect, rtol=5e-03, atol=0.1, equal_nan=True) return (mean, scale, eps), output, expect, compare_tensor(output, expect, rtol=5e-03, atol=0.1, equal_nan=True)
......
...@@ -25,7 +25,7 @@ def prob_regression_run(shape, dtype, kernel_name, attrs): ...@@ -25,7 +25,7 @@ def prob_regression_run(shape, dtype, kernel_name, attrs):
mod = utils.op_build_test(distr_normal_prob_regr_train.prob_regression_train, [x.shape, w.shape, y.shape], mod = utils.op_build_test(distr_normal_prob_regr_train.prob_regression_train, [x.shape, w.shape, y.shape],
[dtype, dtype, dtype], kernel_name=kernel_name, [dtype, dtype, dtype], kernel_name=kernel_name,
op_attrs=[], attrs=None, log_cce=True, dump_cce=True, polyhedral=True) op_attrs=[], attrs=None, log_cce=True, dump_code=True, polyhedral=True)
output = utils.mod_launch(mod, [x, w, y, output], expect=expect) output = utils.mod_launch(mod, [x, w, y, output], expect=expect)
return (x, w, y), output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True) return (x, w, y), output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True)
......
...@@ -83,7 +83,7 @@ def dropout_execute(shape_tensor, keep_prob, dtype, kernel_name, attrs=None): ...@@ -83,7 +83,7 @@ def dropout_execute(shape_tensor, keep_prob, dtype, kernel_name, attrs=None):
output = utils.mod_launch(mod, (input, mask, output), expect=expect) output = utils.mod_launch(mod, (input, mask, output), expect=expect)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
utils.create_cce(kernel_name, "./", source_code) utils.create_code(kernel_name, "./", source_code)
rtol, atol = get_rtol_atol("dropout", dtype) rtol, atol = get_rtol_atol("dropout", dtype)
return (input, mask), output, expect, compare_tensor(output, expect, rtol=rtol, atol=atol, equal_nan=True) return (input, mask), output, expect, compare_tensor(output, expect, rtol=rtol, atol=atol, equal_nan=True)
......
...@@ -28,7 +28,7 @@ def kldiv_loss_grad_run(shape, dtype, kernel_name="kldiv_loss_grad", attrs=None) ...@@ -28,7 +28,7 @@ def kldiv_loss_grad_run(shape, dtype, kernel_name="kldiv_loss_grad", attrs=None)
t = attrs.get("tuning", False) t = attrs.get("tuning", False)
kernel_name = attrs.get("kernel_name", False) kernel_name = attrs.get("kernel_name", False)
mod = utils.op_build_test(kldiv_loss_grad.kldiv_loss_grad, [shape, shape, shape], [dtype, dtype, dtype], mod = utils.op_build_test(kldiv_loss_grad.kldiv_loss_grad, [shape, shape, shape], [dtype, dtype, dtype],
kernel_name=kernel_name, attrs=attrs, dump_cce=True, tuning=t) kernel_name=kernel_name, attrs=attrs, dump_code=True, tuning=t)
if t: if t:
cur_deriv, output, pre_deriv, prediction, target = gen_data(attrs, dtype, shape) cur_deriv, output, pre_deriv, prediction, target = gen_data(attrs, dtype, shape)
return mod, cur_deriv, (pre_deriv, prediction, target, output) return mod, cur_deriv, (pre_deriv, prediction, target, output)
...@@ -36,7 +36,7 @@ def kldiv_loss_grad_run(shape, dtype, kernel_name="kldiv_loss_grad", attrs=None) ...@@ -36,7 +36,7 @@ def kldiv_loss_grad_run(shape, dtype, kernel_name="kldiv_loss_grad", attrs=None)
return mod return mod
else: else:
mod = utils.op_build_test(kldiv_loss_grad.kldiv_loss_grad, [shape, shape, shape], [dtype, dtype, dtype], mod = utils.op_build_test(kldiv_loss_grad.kldiv_loss_grad, [shape, shape, shape], [dtype, dtype, dtype],
kernel_name=kernel_name, attrs=attrs, dump_cce=True) kernel_name=kernel_name, attrs=attrs, dump_code=True)
cur_deriv, output, pre_deriv, prediction, target = gen_data(attrs, dtype, shape) cur_deriv, output, pre_deriv, prediction, target = gen_data(attrs, dtype, shape)
output = utils.mod_launch(mod, (pre_deriv, prediction, target, output), expect=cur_deriv) output = utils.mod_launch(mod, (pre_deriv, prediction, target, output), expect=cur_deriv)
return (pre_deriv, prediction, target), output, cur_deriv, compare_tensor(output, cur_deriv, rtol=0.005, return (pre_deriv, prediction, target), output, cur_deriv, compare_tensor(output, cur_deriv, rtol=0.005,
......
...@@ -28,7 +28,7 @@ def l1_loss_grad_run(shape, dtype, kernel_name="l1_loss_grad", attrs=None): ...@@ -28,7 +28,7 @@ def l1_loss_grad_run(shape, dtype, kernel_name="l1_loss_grad", attrs=None):
t = attrs.get("tuning", False) t = attrs.get("tuning", False)
kernel_name = attrs.get("kernel_name", False) kernel_name = attrs.get("kernel_name", False)
mod = utils.op_build_test(l1_loss_grad.l1_loss_grad, [shape, shape, shape], [dtype, dtype, dtype], mod = utils.op_build_test(l1_loss_grad.l1_loss_grad, [shape, shape, shape], [dtype, dtype, dtype],
kernel_name=kernel_name, attrs=attrs, dump_cce=True, tuning=t) kernel_name=kernel_name, attrs=attrs, dump_code=True, tuning=t)
if t: if t:
dloss, expect, output, prediction, target = gen_data(dtype, shape) dloss, expect, output, prediction, target = gen_data(dtype, shape)
return mod, expect, (dloss, prediction, target, output) return mod, expect, (dloss, prediction, target, output)
...@@ -36,7 +36,7 @@ def l1_loss_grad_run(shape, dtype, kernel_name="l1_loss_grad", attrs=None): ...@@ -36,7 +36,7 @@ def l1_loss_grad_run(shape, dtype, kernel_name="l1_loss_grad", attrs=None):
return mod return mod
else: else:
mod = utils.op_build_test(l1_loss_grad.l1_loss_grad, [shape, shape, shape], [dtype, dtype, dtype], mod = utils.op_build_test(l1_loss_grad.l1_loss_grad, [shape, shape, shape], [dtype, dtype, dtype],
kernel_name=kernel_name, attrs=attrs, dump_cce=True) kernel_name=kernel_name, attrs=attrs, dump_code=True)
dloss, expect, output, prediction, target = gen_data(dtype, shape) dloss, expect, output, prediction, target = gen_data(dtype, shape)
output = utils.mod_launch(mod, (dloss, prediction, target, output), expect=expect) output = utils.mod_launch(mod, (dloss, prediction, target, output), expect=expect)
return (dloss, prediction, target), output, expect, compare_tensor(output, expect, rtol=0.001, atol=0.001) return (dloss, prediction, target), output, expect, compare_tensor(output, expect, rtol=0.001, atol=0.001)
......
...@@ -45,7 +45,7 @@ def matmul_run_mansch(MatrixShape, l1_tiling, l0_tiling, kernel_name, attrs=None ...@@ -45,7 +45,7 @@ def matmul_run_mansch(MatrixShape, l1_tiling, l0_tiling, kernel_name, attrs=None
# launch the kernel # launch the kernel
mod = matmul_mansch.gemm_dsl(MatrixShape, l1_tiling, l0_tiling, kernel_name) mod = matmul_mansch.gemm_dsl(MatrixShape, l1_tiling, l0_tiling, kernel_name)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
utils.create_cce(kernel_name, ".", source_code) utils.create_code(kernel_name, ".", source_code)
res = utils.mod_launch(mod, [A, B, out_data]) res = utils.mod_launch(mod, [A, B, out_data])
# transform numpy data to compute benchMark # transform numpy data to compute benchMark
......
...@@ -44,14 +44,14 @@ def maxpool_ad_run(shape, kernel, stride, pad, dtype, optimized, polyhedral=Fals ...@@ -44,14 +44,14 @@ def maxpool_ad_run(shape, kernel, stride, pad, dtype, optimized, polyhedral=Fals
else: else:
mod = utils.op_build_test(maxpool_ad_no_custom_diff_poly_all_max, [head.shape, shape], mod = utils.op_build_test(maxpool_ad_no_custom_diff_poly_all_max, [head.shape, shape],
[dtype, dtype], kernel_name="maxpool_ad_no_custom_diff_poly_all_max", [dtype, dtype], kernel_name="maxpool_ad_no_custom_diff_poly_all_max",
op_attrs=[kernel, stride, pad], attrs=attrs, log_cce=False, dump_cce=True, polyhedral=polyhedral) op_attrs=[kernel, stride, pad], attrs=attrs, log_cce=False, dump_code=True, polyhedral=polyhedral)
output = utils.mod_launch(mod, [head, input, output], expect=expect) output = utils.mod_launch(mod, [head, input, output], expect=expect)
else: else:
if optimized: if optimized:
if first_max: if first_max:
mod = utils.op_build_test(maxpool_ad, [head.shape, shape, forward.shape, mask.shape], mod = utils.op_build_test(maxpool_ad, [head.shape, shape, forward.shape, mask.shape],
[dtype, dtype, dtype, dtype], kernel_name="maxpool_ad_first_max", [dtype, dtype, dtype, dtype], kernel_name="maxpool_ad_first_max",
op_attrs=[kernel, stride, pad], attrs=attrs, log_cce=False, dump_cce=True, polyhedral=polyhedral) op_attrs=[kernel, stride, pad], attrs=attrs, log_cce=False, dump_code=True, polyhedral=polyhedral)
output = utils.mod_launch(mod, [head, input, forward, mask, output], expect=expect) output = utils.mod_launch(mod, [head, input, forward, mask, output], expect=expect)
else: else:
mod = maxpool_ad_manual_schedule_all_max(shape, kernel, stride, pad, dtype, attrs=attrs, polyhedral=polyhedral) mod = maxpool_ad_manual_schedule_all_max(shape, kernel, stride, pad, dtype, attrs=attrs, polyhedral=polyhedral)
...@@ -62,7 +62,7 @@ def maxpool_ad_run(shape, kernel, stride, pad, dtype, optimized, polyhedral=Fals ...@@ -62,7 +62,7 @@ def maxpool_ad_run(shape, kernel, stride, pad, dtype, optimized, polyhedral=Fals
else: else:
mod = utils.op_build_test(maxpool_ad_no_custom_diff_manual_schedule_all_max, [head.shape, shape], mod = utils.op_build_test(maxpool_ad_no_custom_diff_manual_schedule_all_max, [head.shape, shape],
[dtype, dtype], kernel_name="maxpool_ad_no_custom_diff_manual_schedule_all_max", [dtype, dtype], kernel_name="maxpool_ad_no_custom_diff_manual_schedule_all_max",
op_attrs=[kernel, stride, pad], attrs=attrs, log_cce=False, dump_cce=True, polyhedral=polyhedral) op_attrs=[kernel, stride, pad], attrs=attrs, log_cce=False, dump_code=True, polyhedral=polyhedral)
output = utils.mod_launch(mod, [head, input, output], expect=expect) output = utils.mod_launch(mod, [head, input, output], expect=expect)
if 'tuning' in attrs.keys(): if 'tuning' in attrs.keys():
......
...@@ -100,7 +100,7 @@ def maxpool_grad_run(shape, kernel, stride, pad, dtype, attrs): ...@@ -100,7 +100,7 @@ def maxpool_grad_run(shape, kernel, stride, pad, dtype, attrs):
mod = utils.op_build_test(maxpool_grad.maxpool_grad, mod = utils.op_build_test(maxpool_grad.maxpool_grad,
[shape, y_shape, y_shape], [dtype, dtype, dtype], [shape, y_shape, y_shape], [dtype, dtype, dtype],
op_attrs=[kernel, stride, pad], op_attrs=[kernel, stride, pad],
kernel_name=kernel_name, attrs=attrs, dump_cce=True, tuning=t) kernel_name=kernel_name, attrs=attrs, dump_code=True, tuning=t)
if t: if t:
dy, expect, output, x, y = \ dy, expect, output, x, y = \
gen_data(dtype, kernel, pad, shape, stride, y_shape) gen_data(dtype, kernel, pad, shape, stride, y_shape)
...@@ -111,7 +111,7 @@ def maxpool_grad_run(shape, kernel, stride, pad, dtype, attrs): ...@@ -111,7 +111,7 @@ def maxpool_grad_run(shape, kernel, stride, pad, dtype, attrs):
mod = utils.op_build_test(maxpool_grad.maxpool_grad, mod = utils.op_build_test(maxpool_grad.maxpool_grad,
[shape, y_shape, y_shape], [dtype, dtype, dtype], [shape, y_shape, y_shape], [dtype, dtype, dtype],
op_attrs=[kernel, stride, pad], op_attrs=[kernel, stride, pad],
kernel_name='maxpool_grad', attrs=attrs, dump_cce=True) kernel_name='maxpool_grad', attrs=attrs, dump_code=True)
dy, expect, output, x, y = \ dy, expect, output, x, y = \
gen_data(dtype, kernel, pad, shape, stride, y_shape) gen_data(dtype, kernel, pad, shape, stride, y_shape)
output = utils.mod_launch(mod, (x, y, dy, output), expect=expect) output = utils.mod_launch(mod, (x, y, dy, output), expect=expect)
......
...@@ -31,7 +31,7 @@ def maxpool_grad_with_argmax_run(shape, kernel, stride, pad, dtype, polyhedral=F ...@@ -31,7 +31,7 @@ def maxpool_grad_with_argmax_run(shape, kernel, stride, pad, dtype, polyhedral=F
mod = utils.op_build_test(maxpool_grad_with_argmax, [head.shape, mask.shape], mod = utils.op_build_test(maxpool_grad_with_argmax, [head.shape, mask.shape],
[dtype, dtype], kernel_name="maxpool_grad_with_argmax", [dtype, dtype], kernel_name="maxpool_grad_with_argmax",
op_attrs=[shape, kernel, stride, pad], attrs=attrs, op_attrs=[shape, kernel, stride, pad], attrs=attrs,
log_cce=False, dump_cce=True, polyhedral=polyhedral) log_cce=False, dump_code=True, polyhedral=polyhedral)
if t: if t:
return mod, expect, (head, mask, output) return mod, expect, (head, mask, output)
else: else:
...@@ -43,7 +43,7 @@ def maxpool_grad_with_argmax_run(shape, kernel, stride, pad, dtype, polyhedral=F ...@@ -43,7 +43,7 @@ def maxpool_grad_with_argmax_run(shape, kernel, stride, pad, dtype, polyhedral=F
mod = utils.op_build_test(maxpool_grad_with_argmax, [head.shape, mask.shape], mod = utils.op_build_test(maxpool_grad_with_argmax, [head.shape, mask.shape],
[dtype, dtype], kernel_name="maxpool_grad_with_argmax", [dtype, dtype], kernel_name="maxpool_grad_with_argmax",
op_attrs=[shape, kernel, stride, pad], attrs=attrs, op_attrs=[shape, kernel, stride, pad], attrs=attrs,
log_cce=False, dump_cce=True, polyhedral=polyhedral) log_cce=False, dump_code=True, polyhedral=polyhedral)
output = utils.mod_launch(mod, [head, mask, output], expect=expect) output = utils.mod_launch(mod, [head, mask, output], expect=expect)
rtol, atol = get_rtol_atol("maxpool_grad_with_argmax", dtype) rtol, atol = get_rtol_atol("maxpool_grad_with_argmax", dtype)
......
...@@ -94,6 +94,6 @@ def nms_run(shape_tensor, thres, dtype, kernel_name, attrs): ...@@ -94,6 +94,6 @@ def nms_run(shape_tensor, thres, dtype, kernel_name, attrs):
output = utils.mod_launch(mod, (anchor, output), expect=expect) output = utils.mod_launch(mod, (anchor, output), expect=expect)
output = np.frombuffer(output.tobytes(), np.uint16).reshape(out_shape) output = np.frombuffer(output.tobytes(), np.uint16).reshape(out_shape)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
utils.create_cce(kernel_name, "./", source_code) utils.create_code(kernel_name, "./", source_code)
expect = np.frombuffer(expect.tobytes(), np.uint16).reshape(out_shape) expect = np.frombuffer(expect.tobytes(), np.uint16).reshape(out_shape)
return anchor, output, expect, np.all(output == expect) return anchor, output, expect, np.all(output == expect)
...@@ -32,7 +32,7 @@ def roipool_run(shape, roibox, pooled_shape, dtype, attrs, cce_path="./"): ...@@ -32,7 +32,7 @@ def roipool_run(shape, roibox, pooled_shape, dtype, attrs, cce_path="./"):
expect = roipool_expect(input1, shape, roibox, pooled_shape) expect = roipool_expect(input1, shape, roibox, pooled_shape)
# source_code = mod.imported_modules[0].get_source() # source_code = mod.imported_modules[0].get_source()
# utils.create_cce(kernel_name, cce_path, source_code) # utils.create_code(kernel_name, cce_path, source_code)
output = np.full(output_shape, np.nan, dtype) output = np.full(output_shape, np.nan, dtype)
output = utils.mod_launch(mod, (input1, output), expect=expect) output = utils.mod_launch(mod, (input1, output), expect=expect)
......
...@@ -37,7 +37,7 @@ def smooth_l1_loss_grad_run(shape, dtype, attrs=None, kernel_name="smooth_l1_los ...@@ -37,7 +37,7 @@ def smooth_l1_loss_grad_run(shape, dtype, attrs=None, kernel_name="smooth_l1_los
kernel_name = attrs.get("kernel_name", False) kernel_name = attrs.get("kernel_name", False)
mod = utils.op_build_test(smooth_l1_loss_grad.smooth_l1_loss_grad, [sample_shape, shape, shape, sample_shape], mod = utils.op_build_test(smooth_l1_loss_grad.smooth_l1_loss_grad, [sample_shape, shape, shape, sample_shape],
[dtype, dtype, dtype, anchor_samples_dtype], op_attrs=[sigma, anchor_sample_correct], [dtype, dtype, dtype, anchor_samples_dtype], op_attrs=[sigma, anchor_sample_correct],
attrs=attrs, kernel_name=kernel_name, dump_cce=True, tuning=t) attrs=attrs, kernel_name=kernel_name, dump_code=True, tuning=t)
if t: if t:
anchor_samples, dloss, expect, output, prediction, prediction_, target, target_ = gen_data( anchor_samples, dloss, expect, output, prediction, prediction_, target, target_ = gen_data(
anchor_sample_correct, anchor_samples_dtype, dtype, sample_shape, shape, sigma) anchor_sample_correct, anchor_samples_dtype, dtype, sample_shape, shape, sigma)
...@@ -50,7 +50,7 @@ def smooth_l1_loss_grad_run(shape, dtype, attrs=None, kernel_name="smooth_l1_los ...@@ -50,7 +50,7 @@ def smooth_l1_loss_grad_run(shape, dtype, attrs=None, kernel_name="smooth_l1_los
mod = utils.op_build_test(smooth_l1_loss_grad.smooth_l1_loss_grad, mod = utils.op_build_test(smooth_l1_loss_grad.smooth_l1_loss_grad,
[sample_shape, shape, shape, sample_shape], [sample_shape, shape, shape, sample_shape],
[dtype, dtype, dtype, anchor_samples_dtype], op_attrs=[sigma, anchor_sample_correct], [dtype, dtype, dtype, anchor_samples_dtype], op_attrs=[sigma, anchor_sample_correct],
attrs=attrs, kernel_name=kernel_name, dump_cce=True) attrs=attrs, kernel_name=kernel_name, dump_code=True)
output = utils.mod_launch(mod, (dloss, prediction, target, anchor_samples, output), expect=expect) output = utils.mod_launch(mod, (dloss, prediction, target, anchor_samples, output), expect=expect)
return (dloss, prediction, target, anchor_samples), output, expect, compare_tensor(output, expect, atol=5e-3, return (dloss, prediction, target, anchor_samples), output, expect, compare_tensor(output, expect, atol=5e-3,
rtol=5e-3) rtol=5e-3)
......
...@@ -35,7 +35,7 @@ def square_difference_run(shape1, shape2, dtype, kernel_name, attrs, cce_path=". ...@@ -35,7 +35,7 @@ def square_difference_run(shape1, shape2, dtype, kernel_name, attrs, cce_path=".
input_types=[dtype, dtype], kernel_name=kernel_name, attrs=attrs) input_types=[dtype, dtype], kernel_name=kernel_name, attrs=attrs)
expect, input1, input2, output = gen_data(dtype, shape1, shape2) expect, input1, input2, output = gen_data(dtype, shape1, shape2)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
utils.create_cce(kernel_name, cce_path, source_code) utils.create_code(kernel_name, cce_path, source_code)
output = utils.mod_launch(mod, (input1, input2, output), expect=expect) output = utils.mod_launch(mod, (input1, input2, output), expect=expect)
return (input1, input2), output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True) return (input1, input2), output, expect, compare_tensor(output, expect, rtol=5e-03, equal_nan=True)
......
...@@ -81,7 +81,7 @@ def gen_data(begin, begin_mask, dtype, ellipsis_mask, end, end_mask, grad_shape, ...@@ -81,7 +81,7 @@ def gen_data(begin, begin_mask, dtype, ellipsis_mask, end, end_mask, grad_shape,
# source_code = mod.imported_modules[0].get_source() # source_code = mod.imported_modules[0].get_source()
# print(source_code) # print(source_code)
# kernel_name = "cce_strided_slice_grad_fp16" # kernel_name = "cce_strided_slice_grad_fp16"
# utils.create_cce(kernel_name, './', source_code) # utils.create_code(kernel_name, './', source_code)
out_shape = input_shape out_shape = input_shape
output = np.full(out_shape, 0, dtype) output = np.full(out_shape, 0, dtype)
return expect, grad, output return expect, grad, output
......
...@@ -26,7 +26,7 @@ def truncatemod_run(shape1, shape2, dtype, attrs): ...@@ -26,7 +26,7 @@ def truncatemod_run(shape1, shape2, dtype, attrs):
t = attrs.get("tuning", False) t = attrs.get("tuning", False)
kernel_name = attrs.get("kernel_name", False) kernel_name = attrs.get("kernel_name", False)
mod = utils.op_build_test(truncatemod.truncatemod, [shape1, shape2], [dtype, dtype], kernel_name=kernel_name, mod = utils.op_build_test(truncatemod.truncatemod, [shape1, shape2], [dtype, dtype], kernel_name=kernel_name,
attrs=attrs, dump_cce=True, tuning=t) attrs=attrs, dump_code=True, tuning=t)
if t: if t:
expect, input1, input2, output = gen_data(dtype, shape1, shape2) expect, input1, input2, output = gen_data(dtype, shape1, shape2)
return mod, expect, (input1, input2, output) return mod, expect, (input1, input2, output)
...@@ -35,7 +35,7 @@ def truncatemod_run(shape1, shape2, dtype, attrs): ...@@ -35,7 +35,7 @@ def truncatemod_run(shape1, shape2, dtype, attrs):
else: else:
expect, input1, input2, output = gen_data(dtype, shape1, shape2) expect, input1, input2, output = gen_data(dtype, shape1, shape2)
mod = utils.op_build_test(truncatemod.truncatemod, [shape1, shape2], [dtype, dtype], kernel_name="truncatemod", mod = utils.op_build_test(truncatemod.truncatemod, [shape1, shape2], [dtype, dtype], kernel_name="truncatemod",
attrs=attrs, dump_cce=True) attrs=attrs, dump_code=True)
output = utils.mod_launch(mod, (input1, input2, output), expect=expect) output = utils.mod_launch(mod, (input1, input2, output), expect=expect)
rtol, atol = get_rtol_atol("truncatemod", dtype) rtol, atol = get_rtol_atol("truncatemod", dtype)
res = compare_tensor(output, expect, rtol=rtol, atol=atol, equal_nan=True) res = compare_tensor(output, expect, rtol=rtol, atol=atol, equal_nan=True)
......
...@@ -145,7 +145,7 @@ def vector_matmul_run(case_index, m, n, k, trans_a, trans_b, read_data, dump_dat ...@@ -145,7 +145,7 @@ def vector_matmul_run(case_index, m, n, k, trans_a, trans_b, read_data, dump_dat
# k = (k+15)//16*16 # k = (k+15)//16*16
mod, out_shape = vector_matmul.vector_matmul(m, n, k, trans_a, trans_b, dtype, kernel_name, attrs) mod, out_shape = vector_matmul.vector_matmul(m, n, k, trans_a, trans_b, dtype, kernel_name, attrs)
utils.create_cce(kernel_name, "./", mod.imported_modules[0].get_source()) utils.create_code(kernel_name, "./", mod.imported_modules[0].get_source())
# Generate data # Generate data
m_a, m_b, bench_mark = vector_matmul_data(case_index, m, n, k, trans_a, trans_b, read_data, dump_data, dtype) m_a, m_b, bench_mark = vector_matmul_data(case_index, m, n, k, trans_a, trans_b, read_data, dump_data, dtype)
......
...@@ -35,7 +35,7 @@ def winograd_ad_run(filter_shape, tile, dtype, attrs): ...@@ -35,7 +35,7 @@ def winograd_ad_run(filter_shape, tile, dtype, attrs):
t = attrs.get("tuning", False) t = attrs.get("tuning", False)
kernel_name = attrs.get("kernel_name", False) kernel_name = attrs.get("kernel_name", False)
mod = utils.op_build_test(winograd_ad, [head_np.shape, filter_shape], [dtype, dtype], kernel_name=kernel_name, mod = utils.op_build_test(winograd_ad, [head_np.shape, filter_shape], [dtype, dtype], kernel_name=kernel_name,
attrs=attrs, log_cce=True, dump_cce=True, tuning=t) attrs=attrs, log_cce=True, dump_code=True, tuning=t)
if t: if t:
expect, input_np, output = gen_data(filter_shape, RANGEFILL, dtype) expect, input_np, output = gen_data(filter_shape, RANGEFILL, dtype)
return mod, expect, (head_np, input_np, output) return mod, expect, (head_np, input_np, output)
...@@ -45,7 +45,7 @@ def winograd_ad_run(filter_shape, tile, dtype, attrs): ...@@ -45,7 +45,7 @@ def winograd_ad_run(filter_shape, tile, dtype, attrs):
# scenario 1: # scenario 1:
expect, input_np, output = gen_data(filter_shape, RANGEFILL, dtype) expect, input_np, output = gen_data(filter_shape, RANGEFILL, dtype)
mod = utils.op_build_test(winograd_ad, [head_np.shape, filter_shape], [dtype, dtype], kernel_name="winograd_ad", mod = utils.op_build_test(winograd_ad, [head_np.shape, filter_shape], [dtype, dtype], kernel_name="winograd_ad",
attrs=attrs, log_cce=True, dump_cce=True) attrs=attrs, log_cce=True, dump_code=True)
output = utils.mod_launch(mod, [head_np, input_np, output], expect=expect) output = utils.mod_launch(mod, [head_np, input_np, output], expect=expect)
if not compare_tensor(output, expect, atol=0.1): if not compare_tensor(output, expect, atol=0.1):
return [head_np, input_np], output, expect, compare_tensor(output, expect, rtol=5e-03, atol=5e-03, return [head_np, input_np], output, expect, compare_tensor(output, expect, rtol=5e-03, atol=5e-03,
......
...@@ -403,7 +403,7 @@ def test_CCE_Conv(fmap_shape, filter_shape, pad_, stride_, ...@@ -403,7 +403,7 @@ def test_CCE_Conv(fmap_shape, filter_shape, pad_, stride_,
mod = akg.build(s, [A, B, ScaleQ, OffsetQ, out], "cce", name=kernel_name, attrs=attrs, attrs={"dim": info}, polyhedral=True) mod = akg.build(s, [A, B, ScaleQ, OffsetQ, out], "cce", name=kernel_name, attrs=attrs, attrs={"dim": info}, polyhedral=True)
source_code = mod.imported_modules[0].get_source() source_code = mod.imported_modules[0].get_source()
# print(source_code) # print(source_code)
# utils.create_cce(kernel_name, cce_path, source_code) # utils.create_code(kernel_name, cce_path, source_code)
if run_cce: if run_cce:
run_conv(mod, fmap_shape, filter_shape, pad_[0], stride_[0], use_bias) run_conv(mod, fmap_shape, filter_shape, pad_[0], stride_[0], use_bias)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册