コード例 #1
0
def main(args):
    options = parser.parse_args(args)

    with codecs.open(options.spec, "r", encoding="utf-8") as spec_file:
        spec_yaml = yaml.safe_load(spec_file)
        if not isinstance(spec_yaml, list):
            raise ValueError("expected a list of micro-kernels in the spec")

        spec_name = os.path.splitext(os.path.split(options.spec)[1])[0]
        microkernel_header = {
            "VAddMicrokernelTester": "xnnpack/vadd.h",
            "VAddCMicrokernelTester": "xnnpack/vadd.h",
            "VBinOpMicrokernelTester": "xnnpack/vbinary.h",
            "VBinOpCMicrokernelTester": "xnnpack/vbinary.h",
        }[options.tester]
        tester_header = {
            "VAddMicrokernelTester": "vadd-microkernel-tester.h",
            "VAddCMicrokernelTester": "vaddc-microkernel-tester.h",
            "VBinOpMicrokernelTester": "vbinary-microkernel-tester.h",
            "VBinOpCMicrokernelTester": "vbinaryc-microkernel-tester.h",
        }[options.tester]
        tests = """\
// Copyright 2019 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
//
// Auto-generated file. Do not edit!
//   Specification: {specification}
//   Generator: {generator}


#include <gtest/gtest.h>

#include <xnnpack/common.h>
#include <xnnpack/isa-checks.h>

#include <{microkernel_header}>
#include "{tester_header}"
""".format(specification=options.spec,
           generator=sys.argv[0],
           microkernel_header=microkernel_header,
           tester_header=tester_header)

        for ukernel_spec in spec_yaml:
            name = ukernel_spec["name"]
            op_type, activation_type, batch_tile, arch, isa = split_ukernel_name(
                name)

            # specification can override architecture
            arch = ukernel_spec.get("arch", arch)

            test_case = generate_test_cases(name, op_type, activation_type,
                                            options.tester, batch_tile, isa)
            tests += "\n\n" + xnncommon.postprocess_test_case(
                test_case, arch, isa)

        with codecs.open(options.output, "w", encoding="utf-8") as output_file:
            output_file.write(tests)
コード例 #2
0
def main(args):
    options = parser.parse_args(args)

    with codecs.open(options.spec, "r", encoding="utf-8") as spec_file:
        spec_yaml = yaml.safe_load(spec_file)
        if not isinstance(spec_yaml, list):
            raise ValueError("expected a list of micro-kernels in the spec")

        tests = """\
// Copyright (c) Facebook, Inc. and its affiliates.
// All rights reserved.
//
// Copyright 2019 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
//
// Auto-generated file. Do not edit!
//   Specification: {specification}
//   Generator: {generator}


#include <gtest/gtest.h>

#include <xnnpack/common.h>
#include <xnnpack/isa-checks.h>

#include <xnnpack/dwconv.h>
#include "dwconv-microkernel-tester.h"
""".format(specification=options.spec, generator=sys.argv[0])

        for ukernel_spec in spec_yaml:
            name = ukernel_spec["name"]
            init_fn = ukernel_spec.get("init")
            pipelined = bool(ukernel_spec.get("pipelined", False))
            assembly = bool(ukernel_spec.get("assembly", False))
            primary_tile, cr, kr, requantization, arch, isa = split_ukernel_name(
                name)

            # specification can override architecture
            arch = ukernel_spec.get("arch", arch)

            test_case = generate_test_cases(name, primary_tile, cr, kr, cr,
                                            init_fn, requantization, pipelined,
                                            isa)
            tests += "\n\n" + xnncommon.postprocess_test_case(
                test_case, arch, isa, assembly)

        txt_changed = True
        if os.path.exists(options.output):
            with codecs.open(options.output, "r",
                             encoding="utf-8") as output_file:
                txt_changed = output_file.read() != tests

        if txt_changed:
            with codecs.open(options.output, "w",
                             encoding="utf-8") as output_file:
                output_file.write(tests)
コード例 #3
0
def main(args):
    options = parser.parse_args(args)

    with codecs.open(options.spec, "r", encoding="utf-8") as spec_file:
        spec_yaml = yaml.safe_load(spec_file)
        if not isinstance(spec_yaml, list):
            raise ValueError("expected a list of micro-kernels in the spec")

        tests = """\
// Copyright 2019 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
//
// Auto-generated file. Do not edit!
//   Specification: {specification}
//   Generator: {generator}


#include <gtest/gtest.h>

#include <xnnpack/common.h>
#include <xnnpack/isa-checks.h>

#include <xnnpack/argmaxpool.h>
#include "argmaxpool-microkernel-tester.h"
""".format(specification=options.spec, generator=sys.argv[0])

        for ukernel_spec in spec_yaml:
            name = ukernel_spec["name"]
            primary_tile, incremental_tile, channel_tile, arch, isa = \
              split_ukernel_name(name)

            # specification can override architecture
            arch = ukernel_spec.get("arch", arch)

            test_case = generate_test_cases(name, primary_tile,
                                            incremental_tile, channel_tile,
                                            isa)
            tests += "\n\n" + xnncommon.postprocess_test_case(
                test_case, arch, isa)

        txt_changed = True
        if os.path.exists(options.output):
            with codecs.open(options.output, "r",
                             encoding="utf-8") as output_file:
                txt_changed = output_file.read() != tests

        if txt_changed:
            with codecs.open(options.output, "w",
                             encoding="utf-8") as output_file:
                output_file.write(tests)
コード例 #4
0
def main(args):
    options = parser.parse_args(args)

    with codecs.open(options.spec, "r", encoding="utf-8") as spec_file:
        spec_yaml = yaml.safe_load(spec_file)
        if not isinstance(spec_yaml, list):
            raise ValueError("expected a list of micro-kernels in the spec")

        tests = """\
// Copyright 2020 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
//
// Auto-generated file. Do not edit!
//   Specification: {specification}
//   Generator: {generator}


#include <gtest/gtest.h>

#include <xnnpack/common.h>
#include <xnnpack/isa-checks.h>

#include <xnnpack/dwconv.h>
#include "dwconv2d-microkernel-tester.h"
""".format(specification=options.spec, generator=sys.argv[0])

        for ukernel_spec in spec_yaml:
            name = ukernel_spec["name"]
            pipelined = bool(ukernel_spec.get("pipelined", False))
            assembly = bool(ukernel_spec.get("assembly", False))
            kernel_height, kernel_width, subsampling, padding, arch, isa, \
              height_tile, width_tile = split_ukernel_name(name)

            # specification can override architecture
            arch = ukernel_spec.get("arch", arch)

            test_case = generate_test_cases(name, kernel_height, kernel_width, \
                                            subsampling, padding, isa, \
                                            height_tile, width_tile)
            tests += "\n\n" + xnncommon.postprocess_test_case(
                test_case, arch, isa, assembly)

        with codecs.open(options.output, "w", encoding="utf-8") as output_file:
            output_file.write(tests)
コード例 #5
0
ファイル: generate-gemm-test.py プロジェクト: google/XNNPACK
def main(args):
  options = parser.parse_args(args)
  num_output_files = len(options.output)

  with codecs.open(options.spec, "r", encoding="utf-8") as spec_file:
    spec_yaml = yaml.safe_load(spec_file)
    if not isinstance(spec_yaml, list):
      raise ValueError("expected a list of micro-kernels in the spec")

    tests = """\
// Copyright (c) Facebook, Inc. and its affiliates.
// All rights reserved.
//
// Copyright 2019 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
//
// Auto-generated file. Do not edit!
//   Specification: {specification}
//   Generator: {generator}


#include <gtest/gtest.h>

#include <xnnpack/allocator.h>
#include <xnnpack/common.h>
#include <xnnpack/isa-checks.h>

#include <xnnpack/gemm.h>
#include <xnnpack/igemm.h>
#include <xnnpack/ppmm.h>
#include "gemm-microkernel-tester.h"
""".format(
    specification=options.spec, generator=sys.argv[0])

    outputs = collections.defaultdict(lambda: tests)

    for ukernel_spec in spec_yaml:
      name = ukernel_spec["name"]
      k_block = int(ukernel_spec["k-block"])
      init_fn = ukernel_spec.get("init")
      pipelined = bool(ukernel_spec.get("pipelined", False))
      assembly = bool(ukernel_spec.get("assembly", False))
      jit = name.startswith("xnn_generate")
      mr, nr, kr, sr, xw, requantization, arch, isa = split_ukernel_name(name)

      # specification can override architecture
      arch = ukernel_spec.get("arch", arch)

      test_case = generate_test_cases(name, mr, nr, kr, sr, xw, k_block,
                                      init_fn, requantization, pipelined, isa,
                                      jit)

      # Hash the name of each microkernel and figure out which output file to
      # write it to.
      output_index = zlib.crc32(bytes(name, 'utf-8')) % num_output_files
      outputs[options.output[output_index]] += "\n\n" + xnncommon.postprocess_test_case(
          test_case, arch, isa, assembly, jit)

    for output_name in options.output:
      txt_changed = True
      if os.path.exists(output_name):
        with codecs.open(output_name, "r", encoding="utf-8") as output_file:
          txt_changed = output_file.read() != outputs[output_name]

      if txt_changed:
        with codecs.open(output_name, "w", encoding="utf-8") as output_file:
          output_file.write(outputs[output_name])