blob: 73a5ce43aa4ac0e2df1c018604347485a1a5e41d [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
Pablo Telloa89aa532022-07-26 12:05:04 +010014func isVersionAtLeast(version_name string, target_version int) bool {
SiCong Libf5274d2022-07-20 17:45:36 +010015 name_map := map[string]int {
16 "L": 5, "5": 5,
17 "M": 6, "6": 6,
18 "N": 7, "7": 7,
19 "O": 8, "8": 8,
20 "P": 9, "9": 9,
21 "Q": 10, "10": 10,
22 "R": 11, "11": 11,
23 "S": 12, "12": 12,
24 "T": 13, "13": 13,
25 }
Pablo Telloa89aa532022-07-26 12:05:04 +010026 if _, ok := name_map[version_name]; ok {
27 return name_map[version_name] >= target_version
28 } else {
SiCong Libf5274d2022-07-20 17:45:36 +010029 return false
30 }
SiCong Libf5274d2022-07-20 17:45:36 +010031}
32
Georgios Pinitas41984a02019-12-11 12:05:17 +000033func globalFlags(ctx android.BaseContext) []string {
34 var cppflags []string
35
Pablo Marquez Tello6fc7d522021-07-13 11:09:47 +010036 if ctx.AConfig().PlatformVersionName() == "Q" || ctx.AConfig().PlatformVersionName() == "10" ||
Teresa Charlin65d04482021-02-12 12:29:26 +000037 ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" ||
38 ctx.AConfig().PlatformVersionName() == "S" || ctx.AConfig().PlatformVersionName() == "12" {
Georgios Pinitasfec13b82020-02-26 16:11:32 +000039 cppflags = append(cppflags, "-fno-addrsig")
40 }
41
Pablo Marquez Tellodae5e1e2021-07-22 15:07:54 +010042 if ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" {
Michele Di Giorgiof67034e2021-07-23 12:21:46 +010043 for _, a := range ctx.DeviceConfig().Arches() {
44 theArch := a.ArchType.String()
45 if theArch == "armv8-2a" {
46 cppflags = append(cppflags, "-march=armv8.2-a+fp16")
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +010047 cppflags = append(cppflags, "-DARM_COMPUTE_ENABLE_FP16")
Michele Di Giorgiof67034e2021-07-23 12:21:46 +010048 }
49 }
Pablo Marquez Tellof113f372021-07-20 14:03:42 +010050 }
Pablo Marquez Tello6fc7d522021-07-13 11:09:47 +010051
SiCong Libf5274d2022-07-20 17:45:36 +010052 // Since Android T, the underlying NDK stops supporting system assembler like GAS, in favor of integrated assembler
53 // However for Android < Android T we still want to suppress integrated assembler for backward compatibility
54 if ! isVersionAtLeast(ctx.AConfig().PlatformVersionName(), 13) {
55 cppflags = append(cppflags, "-no-integrated-as")
56 }
57
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010058 data_types := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_TYPE", "ALL"), ",")
59
60 for _, x := range data_types {
Michalis Spyroue9aaacd2021-01-14 13:24:05 +000061 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "INTEGER" {
62 cppflags = append(cppflags, "-DENABLE_INTEGER_KERNELS")
63 }
Michalis Spyrouc4d45552020-10-19 12:41:30 +010064 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8" {
65 cppflags = append(cppflags, "-DENABLE_QASYMM8_KERNELS")
66 }
67 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8_SIGNED" {
68 cppflags = append(cppflags, "-DENABLE_QASYMM8_SIGNED_KERNELS")
69 }
70 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM16" {
71 cppflags = append(cppflags, "-DENABLE_QASYMM16_KERNELS")
72 }
Michalis Spyroue5a41282020-11-03 17:00:04 +000073 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QSYMM16" {
74 cppflags = append(cppflags, "-DENABLE_QSYMM16_KERNELS")
75 }
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010076 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP16" {
77 cppflags = append(cppflags, "-DENABLE_FP16_KERNELS")
78 }
79 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP32" {
80 cppflags = append(cppflags, "-DENABLE_FP32_KERNELS")
81 }
82 }
83
Sheri Zhang79144a62021-02-08 17:43:04 +000084 data_layouts := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_LAYOUT", "ALL"), ",")
85
86 for _, x := range data_layouts {
87 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NHWC" {
88 cppflags = append(cppflags, "-DENABLE_NHWC_KERNELS")
89 }
90 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NCHW" {
91 cppflags = append(cppflags, "-DENABLE_NCHW_KERNELS")
92 }
93 }
94
Pablo Marquez Tello49956cc2021-10-26 14:28:22 +010095 cppflags = append(cppflags, "-DARM_COMPUTE_CPU_ENABLED")
96 cppflags = append(cppflags, "-DARM_COMPUTE_OPENCL_ENABLED")
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000097
Georgios Pinitas41984a02019-12-11 12:05:17 +000098 return cppflags
99}
100
101func clframeworkNNDriverDefaults(ctx android.LoadHookContext) {
102 type props struct {
103 Cppflags []string
104 }
105
106 p := &props{}
107 p.Cppflags = globalFlags(ctx)
108
109 ctx.AppendProperties(p)
110}
111
112func init() {
113
114 android.RegisterModuleType("arm_compute_library_defaults", clframeworkNNDriverDefaultsFactory)
115}
116
117func clframeworkNNDriverDefaultsFactory() android.Module {
118
119 module := cc.DefaultsFactory()
120 android.AddLoadHook(module, clframeworkNNDriverDefaults)
121 return module
122}