Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Max pooling micro-kernels and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marat Dukhan committed Dec 5, 2018
1 parent c6b748a commit 73ac47a
Show file tree
Hide file tree
Showing 11 changed files with 3,127 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ SET(QNNPACK_ARM_NEON_UKERNELS
src/q8avgpool/mp8x9p8q-neon.c
src/q8avgpool/up8x9-neon.c
src/q8avgpool/up8xm-neon.c
src/u8maxpool/16x9p8q-neon.c
src/u8maxpool/sub16-neon.c
src/x8zip/x2-neon.c
src/x8zip/x3-neon.c
src/x8zip/x4-neon.c
Expand Down Expand Up @@ -191,6 +193,8 @@ SET(QNNPACK_X86_SSE2_UKERNELS
src/q8avgpool/mp8x9p8q-sse2.c
src/q8avgpool/up8x9-sse2.c
src/q8avgpool/up8xm-sse2.c
src/u8maxpool/16x9p8q-sse2.c
src/u8maxpool/sub16-sse2.c
src/x8zip/x2-sse2.c
src/x8zip/x3-sse2.c
src/x8zip/x4-sse2.c
Expand Down Expand Up @@ -455,6 +459,15 @@ IF(QNNPACK_BUILD_TESTS)
TARGET_LINK_LIBRARIES(q8gavgpool-test PRIVATE qnnpack cpuinfo fp16 gtest gtest_main)
ADD_TEST(q8gavgpool-test q8gavgpool-test)

ADD_EXECUTABLE(u8maxpool-test test/u8maxpool.cc)
SET_TARGET_PROPERTIES(u8maxpool-test PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)
TARGET_INCLUDE_DIRECTORIES(u8maxpool-test PRIVATE src test)
TARGET_LINK_LIBRARIES(u8maxpool-test PRIVATE qnnpack cpuinfo fp16 gtest gtest_main)
ADD_TEST(u8maxpool-test u8maxpool-test)

ADD_EXECUTABLE(x8zip-test test/x8zip.cc)
SET_TARGET_PROPERTIES(x8zip-test PROPERTIES
CXX_STANDARD 11
Expand Down
5 changes: 5 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def main(args):
build.cc("q8avgpool/mp8x9p8q-neon.c"),
build.cc("q8avgpool/up8x9-neon.c"),
build.cc("q8avgpool/up8xm-neon.c"),
build.cc("u8maxpool/16x9p8q-neon.c"),
build.cc("u8maxpool/sub16-neon.c"),
build.cc("x8zip/x2-neon.c"),
build.cc("x8zip/x3-neon.c"),
build.cc("x8zip/x4-neon.c"),
Expand Down Expand Up @@ -133,6 +135,8 @@ def main(args):
build.cc("q8avgpool/mp8x9p8q-sse2.c"),
build.cc("q8avgpool/up8x9-sse2.c"),
build.cc("q8avgpool/up8xm-sse2.c"),
build.cc("u8maxpool/16x9p8q-sse2.c"),
build.cc("u8maxpool/sub16-sse2.c"),
build.cc("x8zip/x2-sse2.c"),
build.cc("x8zip/x3-sse2.c"),
build.cc("x8zip/x4-sse2.c"),
Expand All @@ -154,6 +158,7 @@ def main(args):
build.unittest("q8avgpool-test", build.cxx("q8avgpool.cc"))
build.unittest("q8gavgpool-test", build.cxx("q8gavgpool.cc"))
build.unittest("q8uvadd-test", build.cxx("q8uvadd.cc"))
build.unittest("u8maxpool-test", build.cxx("u8maxpool.cc"))
build.unittest("hgemm-test", build.cxx("hgemm.cc"))
build.unittest("sgemm-test", build.cxx("sgemm.cc"))
build.unittest("x8zip-test", build.cxx("x8zip.cc"))
Expand Down
29 changes: 29 additions & 0 deletions src/qnnpack/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,25 @@ union qnnp_avgpool_quantization_params {
#endif
};

union qnnp_maxpool_quantization_params {
struct {
int32_t output_max;
int32_t output_min;
} scalar;
#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
struct {
uint8_t output_max;
uint8_t output_min;
} neon;
#endif /* CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 */
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
struct {
QNNP_ALIGN(16) uint8_t output_max[16];
QNNP_ALIGN(16) uint8_t output_min[16];
} sse2;
#endif /* CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 */
};

typedef void (*q8gemm_ukernel_function)(
size_t mr,
size_t nr,
Expand Down Expand Up @@ -383,6 +402,16 @@ typedef void (*q8avgpool_mp_ukernel_function)(
size_t y_increment,
const union qnnp_avgpool_quantization_params* quantization_params);

typedef void (*u8maxpool_ukernel_function)(
size_t n,
size_t ks,
size_t kc,
const uint8_t** x,
uint8_t* y,
size_t x_increment,
size_t y_increment,
const union qnnp_maxpool_quantization_params* quantization_params);

typedef void (*q8uvadd_ukernel_function)(
size_t n,
const uint8_t* a,
Expand Down
22 changes: 22 additions & 0 deletions src/qnnpack/requantization.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,28 @@ static inline union qnnp_avgpool_quantization_params qnnp_compute_scalar_avgpool
return params;
}

static inline union qnnp_maxpool_quantization_params qnnp_compute_maxpool_quantization_params(
uint8_t output_min,
uint8_t output_max)
{
assert(output_min < output_max);

union qnnp_maxpool_quantization_params params;
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
for (uint32_t i = 0; i < 16; i++) {
params.sse2.output_max[i] = output_max;
params.sse2.output_min[i] = output_min;
}
#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
params.neon.output_max = output_max;
params.neon.output_min = output_min;
#else
params.scalar.output_min = (int32_t) (uint32_t) output_min;
params.scalar.output_max = (int32_t) (uint32_t) output_max;
#endif
return params;
}

static inline union qnnp_add_quantization_params qnnp_compute_add_quantization_params(
uint8_t a_zero_point,
uint8_t b_zero_point,
Expand Down
38 changes: 38 additions & 0 deletions src/qnnpack/u8maxpool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <stddef.h>
#include <stdint.h>

#include <qnnpack/params.h>

#ifdef __cplusplus
extern "C" {
#endif

#define DECLARE_U8MAXPOOL_UKERNEL_FUNCTION(fn_name) \
void fn_name( \
size_t n, \
size_t ks, \
size_t kc, \
const uint8_t** x, \
uint8_t* y, \
size_t x_increment, \
size_t y_increment, \
const union qnnp_maxpool_quantization_params* quantization_params);

DECLARE_U8MAXPOOL_UKERNEL_FUNCTION(u8maxpool_ukernel_16x9p8q__neon)
DECLARE_U8MAXPOOL_UKERNEL_FUNCTION(u8maxpool_ukernel_16x9p8q__sse2)
DECLARE_U8MAXPOOL_UKERNEL_FUNCTION(u8maxpool_ukernel_sub16__neon)
DECLARE_U8MAXPOOL_UKERNEL_FUNCTION(u8maxpool_ukernel_sub16__sse2)

#ifdef __cplusplus
} /* extern "C" */
#endif
Loading

0 comments on commit 73ac47a

Please sign in to comment.