Example #1
0
def get_test_lines(test_case, test_params):
    """
    Create a list of strings corresponding to the lines in a single test case.

    Uses TensorFlow to compute the expected results for the given parameters,
    and provides the code to call the test fixture to run the test.
    """
    if test_case.direction == 'forward':
        output, mean, variance, max_input_val = get_result(
            test_case, test_params)
    else:
        output, mean, variance, max_input_val, grad_scale, grad_offset = get_result(
            test_case, test_params)
    camel_case_type = helpers.to_camel_case(test_case.test_type)
    test_case_name = TEST_CASE_TPL.format(
        test_type=camel_case_type,
        direction=helpers.to_camel_case(test_case.direction),
        operation=helpers.to_camel_case(test_case.operation))
    test_name = TEST_NAME_TPL.format(in_s=test_params.in_shape)
    in_shape_init = IN_SHAPE_INIT_TPL.format(test_params.in_shape)
    if test_case.direction == 'forward':
        test_lines = [
            "TYPED_TEST({}, {}) {{".format(test_case_name, test_name),
            "  using DataType = typename TestFixture::DataType;",
            "  const std::vector<DataType> exp_out = {};".format(
                helpers.format_tensor(output)),
            " const std::vector<DataType> mean = {};".format(
                helpers.format_tensor(mean)),
            " const std::vector<DataType> variance = {};".format(
                helpers.format_tensor(variance)),
            "  const std::array<int, 4> in_shape = {};".format(in_shape_init),
            "  const auto params = getBatchNormParams(in_shape, DataFormat::{});"
            .format(test_params.data_format),
            "  const DataType max_input_val = {:.1f};".format(max_input_val),
            "  this->test_batchnorm(exp_out, mean, variance, params, max_input_val);",
            "}",
        ]
        return test_lines
    else:
        test_lines = [
            "TYPED_TEST({}, {}) {{".format(test_case_name, test_name),
            "  using DataType = typename TestFixture::DataType;",
            "  const std::vector<DataType> exp_grad = {};".format(
                helpers.format_tensor(output)),
            " const std::vector<DataType> mean = {};".format(
                helpers.format_tensor(mean)),
            " const std::vector<DataType> variance = {};".format(
                helpers.format_tensor(variance)),
            " const std::vector<DataType> grad_scale = {};".format(
                helpers.format_tensor(grad_scale)),
            " const std::vector<DataType> grad_offset = {};".format(
                helpers.format_tensor(grad_offset)),
            "  const std::array<int, 4> in_shape = {};".format(in_shape_init),
            "  const auto params = getBatchNormParams(in_shape, DataFormat::{});"
            .format(test_params.data_format),
            "  const DataType max_input_val = {:.1f};".format(max_input_val),
            "  this->test_batchnorm(exp_grad, mean, variance, grad_scale, grad_offset, params, max_input_val);",
            "}",
        ]
        return test_lines
def get_test_lines(batch, m, k, n, beta, trans_lhs, trans_rhs):
    """
    Create a list of strings corresponding to the lines in a single test case.

    Uses TensorFlow to compute the expected results for the given parameters,
    and provides the code to call the test fixture to run the test.
    """
    output, max_input_val = helpers.get_result_and_size(get_matmul_result,
                                                        batch=batch,
                                                        m=m,
                                                        k=k,
                                                        n=n,
                                                        beta=beta,
                                                        trans_lhs=trans_lhs,
                                                        trans_rhs=trans_rhs)
    test_case = TEST_CASE_TPL.format(batch=batch,
                                     beta=beta,
                                     trans_lhs=trans_lhs,
                                     trans_rhs=trans_rhs)
    test_name = TEST_NAME_TPL.format(m=m, k=k, n=n)
    test_lines = [
        "TYPED_TEST({}, {}) {{".format(test_case, test_name),
        "  using DataType = typename TestFixture::DataType;",
        "  const std::vector<DataType> exp_out = {};".format(
            helpers.format_tensor(output)),
        "  const int batches = {};".format(batch),
        "  const int m = {};".format(m),
        "  const int k = {};".format(k),
        "  const int n = {};".format(n),
        "  const auto beta = static_cast<DataType>({});".format(beta),
        "  const DataType max_input_val = {:.1f};".format(max_input_val),
        "  this->run(exp_out, batches, m, k, n, beta, 0, 0, 0, max_input_val);",
        "}",
    ]
    return test_lines
Example #3
0
def get_test_lines(test_case, test_params):
    """
    Create a list of strings corresponding to the lines in a single test case.

    Uses TensorFlow to compute the expected results for the given parameters,
    and provides the code to call the test fixture to run the test.
    """
    output, max_input_val = get_result_and_size(test_case, test_params)
    camel_case_type = helpers.to_camel_case(test_case.test_type)
    test_case_name = TEST_CASE_TPL.format(test_type=camel_case_type,
                                          window=test_case.window,
                                          stride=test_case.stride)
    test_name = TEST_NAME_TPL.format(padding=test_params.padding,
                                     in_s=test_params.in_shape,
                                     features=test_params.features)
    in_shape_init = IN_SHAPE_INIT_TPL.format(test_params.in_shape)
    test_lines = [
        "TYPED_TEST({}, {}) {{".format(test_case_name, test_name),
        "  using DataType = typename TestFixture::DataType;",
        "  const std::vector<DataType> exp_out = {};".format(
            helpers.format_tensor(output)),
        "  const std::array<int, 4> in_shape = {};".format(in_shape_init),
        "  const int features = {};".format(test_params.features),
        "  const auto padding = sycldnn::PaddingMode::{};".format(
            test_params.padding),
        "  const DataType max_input_val = {:.1f};".format(max_input_val),
        "  this->run_{}_test(exp_out, in_shape, features, padding, max_input_val);"
        .format(test_case.test_type),
        "}",
    ]
    return test_lines
Example #4
0
def get_test_lines(in_shape, permutation):
    """
    Create a list of strings corresponding to the lines in a single test case.

    Uses TensorFlow to compute the expected results for the given parameters,
    and provides the code to call the test fixture to run the test.
    """
    output, max_input_val = helpers.get_result_and_size(
        get_transpose_result, in_shape=in_shape, permutation=permutation)
    in_shape_str = list(map(str, in_shape))
    perm_str = list(map(str, permutation))
    test_case = TEST_CASE_TPL.format(n_dimensions=len(in_shape))
    test_name = TEST_NAME_TPL.format(n_dimensions=len(in_shape)) + "x".join(
        in_shape_str) + "_" + "x".join(perm_str)
    test_lines = [
        "TYPED_TEST({}, {}) {{".format(test_case, test_name),
        "  using DataType = typename TestFixture::DataType;",
        "  const std::vector<DataType> exp_out = {};".format(
            helpers.format_tensor(output)),
        "  const std::vector<int> sizes = {{ {size_str} }};".format(
            size_str=",".join(in_shape_str)),
        "  const std::vector<int> perm = {{ {perm_str} }};".format(
            perm_str=",".join(perm_str)),
        "  const DataType max_input_val = {:.1f};".format(max_input_val),
        "  this->run(exp_out, sizes, perm, max_input_val, 0, 0);",
        "}",
    ]
    return test_lines
Example #5
0
def get_test_lines(test_case, test_params):
    """
    Create a list of strings corresponding to the lines in a single test case.

    Uses TensorFlow to compute the expected results for the given parameters,
    and provides the code to call the test fixture to run the test.
    """
    output, max_input_val = get_result(test_case, test_params)
    camel_case_type = helpers.to_camel_case(test_case.test_type)
    test_case_name = TEST_CASE_TPL.format(test_type=camel_case_type,
                                          direction=helpers.to_camel_case(
                                              test_case.direction))
    test_name = TEST_NAME_TPL.format(in_s=test_params.in_shape)
    in_shape_init = IN_SHAPE_INIT_TPL.format(test_params.in_shape)
    test_lines = [
        "TYPED_TEST({}, {}) {{".format(test_case_name, test_name),
        "  using DataType = typename TestFixture::DataType;",
        "  const std::vector<DataType> exp_out = {};".format(
            helpers.format_tensor(output)),
        "  const std::array<int, 4> in_shape = {};".format(in_shape_init),
        "  const auto params = getSoftmaxParams(in_shape, DataFormat::{});".
        format(test_params.data_format),
        "  const DataType max_input_val = {:.1f};".format(max_input_val),
        "  this->test_softmax(exp_out, params, max_input_val);",
        "}",
    ]
    return test_lines
Example #6
0
def get_test_lines(test_case, test_params):
    """
    Create a list of strings corresponding to the lines in a single test case.

    Uses TensorFlow to compute the expected results for the given parameters,
    and provides the code to call the test fixture to run the test.
    """
    output = get_result(test_case, test_params)
    camel_case_type = helpers.to_camel_case(test_case.test_type)
    test_case_name = TEST_CASE_TPL.format(test_type=camel_case_type,
                                          direction=helpers.to_camel_case(
                                              test_case.direction))
    test_name = TEST_NAME_TPL.format(in_s=test_params.in_size)
    test_lines = [
        "TYPED_TEST({}, {}) {{".format(test_case_name, test_name),
        "  using DataType = typename TestFixture::DataType;",
        "  const std::vector<DataType> exp_out = {};".format(
            helpers.format_tensor(output)),
        "  this->test_pointwise(exp_out);",
        "}",
    ]
    return test_lines