Georgios Pinitas | 41984a0 | 2019-12-11 12:05:17 +0000 | [diff] [blame] | 1 | // |
Pablo Marquez Tello | 29dc9fc | 2023-07-19 11:17:29 +0100 | [diff] [blame] | 2 | // Copyright © 2020-2023 Arm Ltd. All rights reserved. |
Georgios Pinitas | 41984a0 | 2019-12-11 12:05:17 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | package arm_compute_library_nn_driver |
| 7 | |
| 8 | import ( |
| 9 | "android/soong/android" |
| 10 | "android/soong/cc" |
Michele Di Giorgio | f0a4e60 | 2020-10-15 11:54:17 +0100 | [diff] [blame] | 11 | "strings" |
Georgios Pinitas | 41984a0 | 2019-12-11 12:05:17 +0000 | [diff] [blame] | 12 | ) |
| 13 | |
Pablo Tello | a89aa53 | 2022-07-26 12:05:04 +0100 | [diff] [blame] | 14 | func isVersionAtLeast(version_name string, target_version int) bool { |
SiCong Li | bf5274d | 2022-07-20 17:45:36 +0100 | [diff] [blame] | 15 | 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 Tello | 29dc9fc | 2023-07-19 11:17:29 +0100 | [diff] [blame] | 25 | "U": 14, "14": 14, |
SiCong Li | bf5274d | 2022-07-20 17:45:36 +0100 | [diff] [blame] | 26 | } |
Pablo Tello | a89aa53 | 2022-07-26 12:05:04 +0100 | [diff] [blame] | 27 | if _, ok := name_map[version_name]; ok { |
| 28 | return name_map[version_name] >= target_version |
| 29 | } else { |
SiCong Li | bf5274d | 2022-07-20 17:45:36 +0100 | [diff] [blame] | 30 | return false |
| 31 | } |
SiCong Li | bf5274d | 2022-07-20 17:45:36 +0100 | [diff] [blame] | 32 | } |
| 33 | |
Georgios Pinitas | 41984a0 | 2019-12-11 12:05:17 +0000 | [diff] [blame] | 34 | func globalFlags(ctx android.BaseContext) []string { |
| 35 | var cppflags []string |
| 36 | |
Pablo Marquez Tello | 6fc7d52 | 2021-07-13 11:09:47 +0100 | [diff] [blame] | 37 | if ctx.AConfig().PlatformVersionName() == "Q" || ctx.AConfig().PlatformVersionName() == "10" || |
Teresa Charlin | 65d0448 | 2021-02-12 12:29:26 +0000 | [diff] [blame] | 38 | ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" || |
| 39 | ctx.AConfig().PlatformVersionName() == "S" || ctx.AConfig().PlatformVersionName() == "12" { |
Georgios Pinitas | fec13b8 | 2020-02-26 16:11:32 +0000 | [diff] [blame] | 40 | cppflags = append(cppflags, "-fno-addrsig") |
| 41 | } |
| 42 | |
Pablo Marquez Tello | dae5e1e | 2021-07-22 15:07:54 +0100 | [diff] [blame] | 43 | if ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" { |
Michele Di Giorgio | f67034e | 2021-07-23 12:21:46 +0100 | [diff] [blame] | 44 | 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 Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 48 | cppflags = append(cppflags, "-DARM_COMPUTE_ENABLE_FP16") |
Pablo Marquez Tello | 7720b90 | 2023-11-29 15:50:23 +0000 | [diff] [blame] | 49 | cppflags = append(cppflags, "-DENABLE_FP16_KERNELS") |
Michele Di Giorgio | f67034e | 2021-07-23 12:21:46 +0100 | [diff] [blame] | 50 | } |
| 51 | } |
Pablo Marquez Tello | f113f37 | 2021-07-20 14:03:42 +0100 | [diff] [blame] | 52 | } |
Pablo Marquez Tello | 6fc7d52 | 2021-07-13 11:09:47 +0100 | [diff] [blame] | 53 | |
SiCong Li | bf5274d | 2022-07-20 17:45:36 +0100 | [diff] [blame] | 54 | // 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 Giorgio | f0a4e60 | 2020-10-15 11:54:17 +0100 | [diff] [blame] | 60 | data_types := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_TYPE", "ALL"), ",") |
| 61 | |
| 62 | for _, x := range data_types { |
Michalis Spyrou | e9aaacd | 2021-01-14 13:24:05 +0000 | [diff] [blame] | 63 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "INTEGER" { |
| 64 | cppflags = append(cppflags, "-DENABLE_INTEGER_KERNELS") |
| 65 | } |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 66 | 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 Spyrou | e5a4128 | 2020-11-03 17:00:04 +0000 | [diff] [blame] | 75 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QSYMM16" { |
| 76 | cppflags = append(cppflags, "-DENABLE_QSYMM16_KERNELS") |
| 77 | } |
Michele Di Giorgio | f0a4e60 | 2020-10-15 11:54:17 +0100 | [diff] [blame] | 78 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP32" { |
| 79 | cppflags = append(cppflags, "-DENABLE_FP32_KERNELS") |
| 80 | } |
| 81 | } |
| 82 | |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 83 | 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 Tello | 49956cc | 2021-10-26 14:28:22 +0100 | [diff] [blame] | 94 | cppflags = append(cppflags, "-DARM_COMPUTE_CPU_ENABLED") |
| 95 | cppflags = append(cppflags, "-DARM_COMPUTE_OPENCL_ENABLED") |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 96 | |
Georgios Pinitas | 41984a0 | 2019-12-11 12:05:17 +0000 | [diff] [blame] | 97 | return cppflags |
| 98 | } |
| 99 | |
| 100 | func 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 | |
| 111 | func init() { |
| 112 | |
| 113 | android.RegisterModuleType("arm_compute_library_defaults", clframeworkNNDriverDefaultsFactory) |
| 114 | } |
| 115 | |
| 116 | func clframeworkNNDriverDefaultsFactory() android.Module { |
| 117 | |
| 118 | module := cc.DefaultsFactory() |
| 119 | android.AddLoadHook(module, clframeworkNNDriverDefaults) |
| 120 | return module |
| 121 | } |