blob: dda77b55df75fff8791d8297d17514d5ba738e78 [file] [log] [blame]
Georgios Pinitas41984a02019-12-11 12:05:17 +00001//
Pablo Marquez Tello29dc9fc2023-07-19 11:17:29 +01002// Copyright © 2020-2023 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,
Pablo Marquez Tello29dc9fc2023-07-19 11:17:29 +010025 "U": 14, "14": 14,
SiCong Libf5274d2022-07-20 17:45:36 +010026 }
Pablo Telloa89aa532022-07-26 12:05:04 +010027 if _, ok := name_map[version_name]; ok {
28 return name_map[version_name] >= target_version
29 } else {
SiCong Libf5274d2022-07-20 17:45:36 +010030 return false
31 }
SiCong Libf5274d2022-07-20 17:45:36 +010032}
33
Georgios Pinitas41984a02019-12-11 12:05:17 +000034func globalFlags(ctx android.BaseContext) []string {
35 var cppflags []string
36
Pablo Marquez Tello6fc7d522021-07-13 11:09:47 +010037 if ctx.AConfig().PlatformVersionName() == "Q" || ctx.AConfig().PlatformVersionName() == "10" ||
Teresa Charlin65d04482021-02-12 12:29:26 +000038 ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" ||
39 ctx.AConfig().PlatformVersionName() == "S" || ctx.AConfig().PlatformVersionName() == "12" {
Georgios Pinitasfec13b82020-02-26 16:11:32 +000040 cppflags = append(cppflags, "-fno-addrsig")
41 }
42
Pablo Marquez Tellodae5e1e2021-07-22 15:07:54 +010043 if ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" {
Michele Di Giorgiof67034e2021-07-23 12:21:46 +010044 for _, a := range ctx.DeviceConfig().Arches() {
45 theArch := a.ArchType.String()
46 if theArch == "armv8-2a" {
47 cppflags = append(cppflags, "-march=armv8.2-a+fp16")
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +010048 cppflags = append(cppflags, "-DARM_COMPUTE_ENABLE_FP16")
Michele Di Giorgiof67034e2021-07-23 12:21:46 +010049 }
50 }
Pablo Marquez Tellof113f372021-07-20 14:03:42 +010051 }
Pablo Marquez Tello6fc7d522021-07-13 11:09:47 +010052
SiCong Libf5274d2022-07-20 17:45:36 +010053 // Since Android T, the underlying NDK stops supporting system assembler like GAS, in favor of integrated assembler
54 // However for Android < Android T we still want to suppress integrated assembler for backward compatibility
55 if ! isVersionAtLeast(ctx.AConfig().PlatformVersionName(), 13) {
56 cppflags = append(cppflags, "-no-integrated-as")
57 }
58
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010059 data_types := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_TYPE", "ALL"), ",")
60
61 for _, x := range data_types {
Michalis Spyroue9aaacd2021-01-14 13:24:05 +000062 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "INTEGER" {
63 cppflags = append(cppflags, "-DENABLE_INTEGER_KERNELS")
64 }
Michalis Spyrouc4d45552020-10-19 12:41:30 +010065 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8" {
66 cppflags = append(cppflags, "-DENABLE_QASYMM8_KERNELS")
67 }
68 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8_SIGNED" {
69 cppflags = append(cppflags, "-DENABLE_QASYMM8_SIGNED_KERNELS")
70 }
71 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM16" {
72 cppflags = append(cppflags, "-DENABLE_QASYMM16_KERNELS")
73 }
Michalis Spyroue5a41282020-11-03 17:00:04 +000074 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QSYMM16" {
75 cppflags = append(cppflags, "-DENABLE_QSYMM16_KERNELS")
76 }
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010077 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP16" {
78 cppflags = append(cppflags, "-DENABLE_FP16_KERNELS")
79 }
80 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP32" {
81 cppflags = append(cppflags, "-DENABLE_FP32_KERNELS")
82 }
83 }
84
Sheri Zhang79144a62021-02-08 17:43:04 +000085 data_layouts := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_LAYOUT", "ALL"), ",")
86
87 for _, x := range data_layouts {
88 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NHWC" {
89 cppflags = append(cppflags, "-DENABLE_NHWC_KERNELS")
90 }
91 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NCHW" {
92 cppflags = append(cppflags, "-DENABLE_NCHW_KERNELS")
93 }
94 }
95
Pablo Marquez Tello49956cc2021-10-26 14:28:22 +010096 cppflags = append(cppflags, "-DARM_COMPUTE_CPU_ENABLED")
97 cppflags = append(cppflags, "-DARM_COMPUTE_OPENCL_ENABLED")
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000098
Georgios Pinitas41984a02019-12-11 12:05:17 +000099 return cppflags
100}
101
102func clframeworkNNDriverDefaults(ctx android.LoadHookContext) {
103 type props struct {
104 Cppflags []string
105 }
106
107 p := &props{}
108 p.Cppflags = globalFlags(ctx)
109
110 ctx.AppendProperties(p)
111}
112
113func init() {
114
115 android.RegisterModuleType("arm_compute_library_defaults", clframeworkNNDriverDefaultsFactory)
116}
117
118func clframeworkNNDriverDefaultsFactory() android.Module {
119
120 module := cc.DefaultsFactory()
121 android.AddLoadHook(module, clframeworkNNDriverDefaults)
122 return module
123}