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 | |
Teresa Charlin | f5ac7bf | 2021-02-12 12:29:26 +0000 | [diff] [blame^] | 17 | if ctx.AConfig().PlatformVersionName() == "Q" || ctx.AConfig().PlatformVersionName() == "10" || |
| 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 | |
Michele Di Giorgio | f0a4e60 | 2020-10-15 11:54:17 +0100 | [diff] [blame] | 23 | data_types := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_TYPE", "ALL"), ",") |
| 24 | |
| 25 | for _, x := range data_types { |
Michalis Spyrou | e9aaacd | 2021-01-14 13:24:05 +0000 | [diff] [blame] | 26 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "INTEGER" { |
| 27 | cppflags = append(cppflags, "-DENABLE_INTEGER_KERNELS") |
| 28 | } |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 29 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8" { |
| 30 | cppflags = append(cppflags, "-DENABLE_QASYMM8_KERNELS") |
| 31 | } |
| 32 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM8_SIGNED" { |
| 33 | cppflags = append(cppflags, "-DENABLE_QASYMM8_SIGNED_KERNELS") |
| 34 | } |
| 35 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QASYMM16" { |
| 36 | cppflags = append(cppflags, "-DENABLE_QASYMM16_KERNELS") |
| 37 | } |
Michalis Spyrou | e5a4128 | 2020-11-03 17:00:04 +0000 | [diff] [blame] | 38 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "QSYMM16" { |
| 39 | cppflags = append(cppflags, "-DENABLE_QSYMM16_KERNELS") |
| 40 | } |
Michele Di Giorgio | f0a4e60 | 2020-10-15 11:54:17 +0100 | [diff] [blame] | 41 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP16" { |
| 42 | cppflags = append(cppflags, "-DENABLE_FP16_KERNELS") |
| 43 | } |
| 44 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "FP32" { |
| 45 | cppflags = append(cppflags, "-DENABLE_FP32_KERNELS") |
| 46 | } |
| 47 | } |
| 48 | |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 49 | data_layouts := strings.Split(ctx.AConfig().GetenvWithDefault("COMPUTE_LIB_DATA_LAYOUT", "ALL"), ",") |
| 50 | |
| 51 | for _, x := range data_layouts { |
| 52 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NHWC" { |
| 53 | cppflags = append(cppflags, "-DENABLE_NHWC_KERNELS") |
| 54 | } |
| 55 | if strings.ToUpper(x) == "ALL" || strings.ToUpper(x) == "NCHW" { |
| 56 | cppflags = append(cppflags, "-DENABLE_NCHW_KERNELS") |
| 57 | } |
| 58 | } |
| 59 | |
Georgios Pinitas | 41984a0 | 2019-12-11 12:05:17 +0000 | [diff] [blame] | 60 | return cppflags |
| 61 | } |
| 62 | |
| 63 | func clframeworkNNDriverDefaults(ctx android.LoadHookContext) { |
| 64 | type props struct { |
| 65 | Cppflags []string |
| 66 | } |
| 67 | |
| 68 | p := &props{} |
| 69 | p.Cppflags = globalFlags(ctx) |
| 70 | |
| 71 | ctx.AppendProperties(p) |
| 72 | } |
| 73 | |
| 74 | func init() { |
| 75 | |
| 76 | android.RegisterModuleType("arm_compute_library_defaults", clframeworkNNDriverDefaultsFactory) |
| 77 | } |
| 78 | |
| 79 | func clframeworkNNDriverDefaultsFactory() android.Module { |
| 80 | |
| 81 | module := cc.DefaultsFactory() |
| 82 | android.AddLoadHook(module, clframeworkNNDriverDefaults) |
| 83 | return module |
| 84 | } |