blob: 2aab2d3fe7f16b4fcd189570e9e071bff1aa34ae [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")
Pablo Marquez Tello7720b902023-11-29 15:50:23 +000049 cppflags = append(cppflags, "-DENABLE_FP16_KERNELS")
Michele Di Giorgiof67034e2021-07-23 12:21:46 +010050 }
51 }
Pablo Marquez Tellof113f372021-07-20 14:03:42 +010052 }
Pablo Marquez Tello6fc7d522021-07-13 11:09:47 +010053
SiCong Libf5274d2022-07-20 17:45:36 +010054 // Since Android T, the underlying NDK stops supporting system assembler like GAS, in favor of integrated assembler
55 // However for Android < Android T we still want to suppress integrated assembler for backward compatibility
56 if ! isVersionAtLeast(ctx.AConfig().PlatformVersionName(), 13) {
57 cppflags = append(cppflags, "-no-integrated-as")
58 }
59
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010060 data_types := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_TYPE", "ALL"), ",")
61
62 for _, x := range data_types {
Michalis Spyroue9aaacd2021-01-14 13:24:05 +000063 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "INTEGER" {
64 cppflags = append(cppflags, "-DENABLE_INTEGER_KERNELS")
65 }
Michalis Spyrouc4d45552020-10-19 12:41:30 +010066 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8" {
67 cppflags = append(cppflags, "-DENABLE_QASYMM8_KERNELS")
68 }
69 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8_SIGNED" {
70 cppflags = append(cppflags, "-DENABLE_QASYMM8_SIGNED_KERNELS")
71 }
72 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM16" {
73 cppflags = append(cppflags, "-DENABLE_QASYMM16_KERNELS")
74 }
Michalis Spyroue5a41282020-11-03 17:00:04 +000075 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QSYMM16" {
76 cppflags = append(cppflags, "-DENABLE_QSYMM16_KERNELS")
77 }
Michele Di Giorgiof0a4e602020-10-15 11:54:17 +010078 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP32" {
79 cppflags = append(cppflags, "-DENABLE_FP32_KERNELS")
80 }
81 }
82
Sheri Zhang79144a62021-02-08 17:43:04 +000083 data_layouts := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_LAYOUT", "ALL"), ",")
84
85 for _, x := range data_layouts {
86 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NHWC" {
87 cppflags = append(cppflags, "-DENABLE_NHWC_KERNELS")
88 }
89 if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NCHW" {
90 cppflags = append(cppflags, "-DENABLE_NCHW_KERNELS")
91 }
92 }
93
Pablo Marquez Tello49956cc2021-10-26 14:28:22 +010094 cppflags = append(cppflags, "-DARM_COMPUTE_CPU_ENABLED")
95 cppflags = append(cppflags, "-DARM_COMPUTE_OPENCL_ENABLED")
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000096
Georgios Pinitas41984a02019-12-11 12:05:17 +000097 return cppflags
98}
99
100func clframeworkNNDriverDefaults(ctx android.LoadHookContext) {
101 type props struct {
102 Cppflags []string
103 }
104
105 p := &props{}
106 p.Cppflags = globalFlags(ctx)
107
108 ctx.AppendProperties(p)
109}
110
111func init() {
112
113 android.RegisterModuleType("arm_compute_library_defaults", clframeworkNNDriverDefaultsFactory)
114}
115
116func clframeworkNNDriverDefaultsFactory() android.Module {
117
118 module := cc.DefaultsFactory()
119 android.AddLoadHook(module, clframeworkNNDriverDefaults)
120 return module
121}