blob: 2461838d4f20afd1fff9c2d14ddd74b04928e64e [file] [log] [blame]
Georgios Pinitas41984a02019-12-11 12:05:17 +00001//
Pablo Marquez Tellof113f372021-07-20 14:03:42 +01002// Copyright © 2020-2021 Arm Ltd. All rights reserved.
Georgios Pinitas41984a02019-12-11 12:05:17 +00003// SPDX-License-Identifier: MIT
4//
5
6package arm_compute_library_nn_driver
7
8import (
9 "android/soong/android"
10 "android/soong/cc"
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010011 "strings"
Georgios Pinitas41984a02019-12-11 12:05:17 +000012)
13
14func globalFlags(ctx android.BaseContext) []string {
15 var cppflags []string
16
Pablo Marquez Tello6fc7d522021-07-13 11:09:47 +010017 if ctx.AConfig().PlatformVersionName() == "Q" || ctx.AConfig().PlatformVersionName() == "10" ||
Teresa Charlin65d04482021-02-12 12:29:26 +000018 ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" ||
19 ctx.AConfig().PlatformVersionName() == "S" || ctx.AConfig().PlatformVersionName() == "12" {
Georgios Pinitasfec13b82020-02-26 16:11:32 +000020 cppflags = append(cppflags, "-fno-addrsig")
21 }
22
Pablo Marquez Tellodae5e1e2021-07-22 15:07:54 +010023 if ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" {
Michele Di Giorgiof67034e2021-07-23 12:21:46 +010024 for _, a := range ctx.DeviceConfig().Arches() {
25 theArch := a.ArchType.String()
26 if theArch == "armv8-2a" {
27 cppflags = append(cppflags, "-march=armv8.2-a+fp16")
28 }
29 }
Pablo Marquez Tellof113f372021-07-20 14:03:42 +010030 }
Pablo Marquez Tello6fc7d522021-07-13 11:09:47 +010031
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010032 data_types := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_TYPE", "ALL"), ",")
33
34 for _, x := range data_types {
Michalis Spyroue9aaacd2021-01-14 13:24:05 +000035 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "INTEGER" {
36 cppflags = append(cppflags, "-DENABLE_INTEGER_KERNELS")
37 }
Michalis Spyrouc4d45552020-10-19 12:41:30 +010038 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8" {
39 cppflags = append(cppflags, "-DENABLE_QASYMM8_KERNELS")
40 }
41 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8_SIGNED" {
42 cppflags = append(cppflags, "-DENABLE_QASYMM8_SIGNED_KERNELS")
43 }
44 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM16" {
45 cppflags = append(cppflags, "-DENABLE_QASYMM16_KERNELS")
46 }
Michalis Spyroue5a41282020-11-03 17:00:04 +000047 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QSYMM16" {
48 cppflags = append(cppflags, "-DENABLE_QSYMM16_KERNELS")
49 }
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010050 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP16" {
51 cppflags = append(cppflags, "-DENABLE_FP16_KERNELS")
52 }
53 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP32" {
54 cppflags = append(cppflags, "-DENABLE_FP32_KERNELS")
55 }
56 }
57
Sheri Zhang79144a62021-02-08 17:43:04 +000058 data_layouts := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_LAYOUT", "ALL"), ",")
59
60 for _, x := range data_layouts {
61 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NHWC" {
62 cppflags = append(cppflags, "-DENABLE_NHWC_KERNELS")
63 }
64 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NCHW" {
65 cppflags = append(cppflags, "-DENABLE_NCHW_KERNELS")
66 }
67 }
68
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000069 cppflags = append(cppflags, "-ARM_COMPUTE_CPU_ENABLED")
70 cppflags = append(cppflags, "-ARM_COMPUTE_OPENCL_ENABLED")
71
Georgios Pinitas41984a02019-12-11 12:05:17 +000072 return cppflags
73}
74
75func clframeworkNNDriverDefaults(ctx android.LoadHookContext) {
76 type props struct {
77 Cppflags []string
78 }
79
80 p := &props{}
81 p.Cppflags = globalFlags(ctx)
82
83 ctx.AppendProperties(p)
84}
85
86func init() {
87
88 android.RegisterModuleType("arm_compute_library_defaults", clframeworkNNDriverDefaultsFactory)
89}
90
91func clframeworkNNDriverDefaultsFactory() android.Module {
92
93 module := cc.DefaultsFactory()
94 android.AddLoadHook(module, clframeworkNNDriverDefaults)
95 return module
96}