Georgios Pinitas | 41984a0 | 2019-12-11 12:05:17 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 ARM Ltd. All rights reserved. |
| 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 | |
| 14 | func globalFlags(ctx android.BaseContext) []string { |
| 15 | var cppflags []string |
| 16 | |
Pablo Marquez Tello | 6fc7d52 | 2021-07-13 11:09:47 +0100 | [diff] [blame^] | 17 | if ctx.AConfig().PlatformVersionName() == "Q" || ctx.AConfig().PlatformVersionName() == "10" || |
Teresa Charlin | 65d0448 | 2021-02-12 12:29:26 +0000 | [diff] [blame] | 18 | ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11" || |
| 19 | ctx.AConfig().PlatformVersionName() == "S" || ctx.AConfig().PlatformVersionName() == "12" { |
Georgios Pinitas | fec13b8 | 2020-02-26 16:11:32 +0000 | [diff] [blame] | 20 | cppflags = append(cppflags, "-fno-addrsig") |
| 21 | } |
| 22 | |
Pablo Marquez Tello | 6fc7d52 | 2021-07-13 11:09:47 +0100 | [diff] [blame^] | 23 | if (ctx.AConfig().PlatformVersionName() == "R" || ctx.AConfig().PlatformVersionName() == "11") && |
| 24 | (ctx.AConfig().DevicePrimaryArchType().String() == "armv8-2a") { |
| 25 | cppflags = append(cppflags, "-march=armv8.2-a+fp16") |
| 26 | } |
| 27 | |
Michele Di Giorgio | f0a4e60 | 2020-10-15 11:54:17 +0100 | [diff] [blame] | 28 | data_types := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_TYPE", "ALL"), ",") |
| 29 | |
| 30 | for _, x := range data_types { |
Michalis Spyrou | e9aaacd | 2021-01-14 13:24:05 +0000 | [diff] [blame] | 31 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "INTEGER" { |
| 32 | cppflags = append(cppflags, "-DENABLE_INTEGER_KERNELS") |
| 33 | } |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 34 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8" { |
| 35 | cppflags = append(cppflags, "-DENABLE_QASYMM8_KERNELS") |
| 36 | } |
| 37 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8_SIGNED" { |
| 38 | cppflags = append(cppflags, "-DENABLE_QASYMM8_SIGNED_KERNELS") |
| 39 | } |
| 40 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM16" { |
| 41 | cppflags = append(cppflags, "-DENABLE_QASYMM16_KERNELS") |
| 42 | } |
Michalis Spyrou | e5a4128 | 2020-11-03 17:00:04 +0000 | [diff] [blame] | 43 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QSYMM16" { |
| 44 | cppflags = append(cppflags, "-DENABLE_QSYMM16_KERNELS") |
| 45 | } |
Michele Di Giorgio | f0a4e60 | 2020-10-15 11:54:17 +0100 | [diff] [blame] | 46 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP16" { |
| 47 | cppflags = append(cppflags, "-DENABLE_FP16_KERNELS") |
| 48 | } |
| 49 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP32" { |
| 50 | cppflags = append(cppflags, "-DENABLE_FP32_KERNELS") |
| 51 | } |
| 52 | } |
| 53 | |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 54 | data_layouts := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_LAYOUT", "ALL"), ",") |
| 55 | |
| 56 | for _, x := range data_layouts { |
| 57 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NHWC" { |
| 58 | cppflags = append(cppflags, "-DENABLE_NHWC_KERNELS") |
| 59 | } |
| 60 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NCHW" { |
| 61 | cppflags = append(cppflags, "-DENABLE_NCHW_KERNELS") |
| 62 | } |
| 63 | } |
| 64 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 65 | cppflags = append(cppflags, "-ARM_COMPUTE_CPU_ENABLED") |
| 66 | cppflags = append(cppflags, "-ARM_COMPUTE_OPENCL_ENABLED") |
| 67 | |
Georgios Pinitas | 41984a0 | 2019-12-11 12:05:17 +0000 | [diff] [blame] | 68 | return cppflags |
| 69 | } |
| 70 | |
| 71 | func clframeworkNNDriverDefaults(ctx android.LoadHookContext) { |
| 72 | type props struct { |
| 73 | Cppflags []string |
| 74 | } |
| 75 | |
| 76 | p := &props{} |
| 77 | p.Cppflags = globalFlags(ctx) |
| 78 | |
| 79 | ctx.AppendProperties(p) |
| 80 | } |
| 81 | |
| 82 | func init() { |
| 83 | |
| 84 | android.RegisterModuleType("arm_compute_library_defaults", clframeworkNNDriverDefaultsFactory) |
| 85 | } |
| 86 | |
| 87 | func clframeworkNNDriverDefaultsFactory() android.Module { |
| 88 | |
| 89 | module := cc.DefaultsFactory() |
| 90 | android.AddLoadHook(module, clframeworkNNDriverDefaults) |
| 91 | return module |
| 92 | } |