Skip to content

Commit 0b09b1f

Browse files
gonnetxnnpack-bot
authored andcommitted
Clean up the XNN_SLINKY_ENABLED and XNN_SLINKY_AVAILABLE macros to match other similar macros:
* `XNN_SLINKY_ENABLED == 1` (the default on `x86_64-linux` and `aarch64-linux`) now means that Slinky was compiled into XNNPACK, and * `XNN_USE_SLINKY == 1` means that Slinky should be used by default. Explicitly setting `--defines xnn_use_slinky=true` sets both `XNN_SLINKY_ENABLED` and `XNN_USE_SLINKY` to `1`, regardless of the build platform. Explicitly setting `--defines xnn_use_slinky=false` sets `XNN_SLINKY_ENABLED` to `0` PiperOrigin-RevId: 808524347
1 parent deb00e4 commit 0b09b1f

File tree

4 files changed

+70
-35
lines changed

4 files changed

+70
-35
lines changed

BUILD.bazel

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,10 +1261,15 @@ config_setting(
12611261

12621262
# Enables usage of slinky locality optimizations
12631263
config_setting(
1264-
name = "slinky_enabled",
1264+
name = "xnn_use_slinky_explicit_true",
12651265
define_values = {"xnn_use_slinky": "true"},
12661266
)
12671267

1268+
config_setting(
1269+
name = "xnn_use_slinky_explicit_false",
1270+
define_values = {"xnn_use_slinky": "false"},
1271+
)
1272+
12681273
# Enables usage of WASM SIMD AVX-256 revectorization kernels.
12691274
config_setting(
12701275
name = "xnn_enable_wasm_revectorize_explicit_true",
@@ -1755,6 +1760,32 @@ alias(
17551760
}),
17561761
)
17571762

1763+
selects.config_setting_group(
1764+
name = "slinky_enabled_by_default",
1765+
match_any = [
1766+
"//build_config:linux_x86",
1767+
"//build_config:linux_arm64",
1768+
],
1769+
)
1770+
1771+
alias(
1772+
name = "slinky_enabled",
1773+
actual = select({
1774+
":xnn_use_slinky_explicit_true": ":xnn_use_slinky_explicit_true",
1775+
":xnn_use_slinky_explicit_false": ":xnn_use_slinky_explicit_true",
1776+
"//conditions:default": ":slinky_enabled_by_default",
1777+
}),
1778+
)
1779+
1780+
alias(
1781+
name = "use_slinky",
1782+
actual = select({
1783+
":xnn_use_slinky_explicit_true": ":xnn_use_slinky_explicit_true",
1784+
":xnn_use_slinky_explicit_false": ":xnn_use_slinky_explicit_true",
1785+
"//conditions:default": ":xnn_use_slinky_explicit_true",
1786+
}),
1787+
)
1788+
17581789
selects.config_setting_group(
17591790
name = "kleidiai_enabled_by_default",
17601791
match_all = [

src/runtime.c

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "src/xnnpack/common.h"
2929
#include "src/xnnpack/internal.h"
3030
#include "src/xnnpack/log.h"
31+
#include "src/xnnpack/math.h"
3132
#include "src/xnnpack/memory-planner.h"
3233
#include "src/xnnpack/memory.h"
3334
#include "src/xnnpack/microkernel-type.h"
@@ -651,9 +652,9 @@ static enum xnn_status create_runtime_impl(
651652
}
652653

653654
runtime->threadpool = threadpool;
654-
#ifdef XNN_SLINKY_AVAILABLE
655+
#ifdef XNN_SLINKY_ENABLED
655656
runtime->xnn_threadpool = xnn_threadpool;
656-
#endif // XNN_SLINKY_AVAILABLE
657+
#endif // XNN_SLINKY_ENABLED
657658

658659
for (uint32_t i = 0; i < runtime->num_values; i++) {
659660
struct xnn_runtime_value* value = &runtime->values[i];
@@ -704,7 +705,19 @@ enum xnn_status xnn_create_runtime_v4(
704705
return create_runtime_impl(subgraph, weights_cache, workspace, threadpool, /*xnn_threadpool=*/NULL, flags, runtime_out);
705706
}
706707

707-
#ifndef XNN_SLINKY_AVAILABLE
708+
#ifdef XNN_SLINKY_ENABLED
709+
static bool use_slinky(uint32_t flags) {
710+
#ifdef XNN_USE_SLINKY
711+
// If compiling with XNN_USE_SLINKY defined, assume we always
712+
// want Slinky enabled, regardless of the runtime flag
713+
return true;
714+
#else
715+
return (flags & XNN_FLAG_SLINKY_ENABLED) != 0;
716+
#endif // XNN_USE_SLINKY
717+
}
718+
#endif // XNN_SLINKY_ENABLED
719+
720+
#ifndef XNN_SLINKY_ENABLED
708721
enum xnn_status xnn_create_threadpool_v2(
709722
struct xnn_scheduler_v2 scheduler,
710723
void* scheduler_context,
@@ -720,7 +733,7 @@ enum xnn_status xnn_delete_threadpool(xnn_threadpool_t threadpool)
720733
{
721734
return xnn_status_success;
722735
}
723-
#endif
736+
#endif // XNN_SLINKY_ENABLED
724737

725738
enum xnn_status xnn_create_runtime_with_threadpool(
726739
xnn_subgraph_t subgraph,
@@ -731,14 +744,14 @@ enum xnn_status xnn_create_runtime_with_threadpool(
731744
return create_runtime_impl(subgraph, weights_cache, /*workspace=*/NULL, /*threadpool*/NULL, threadpool, flags, runtime_out);
732745
}
733746

734-
#ifndef XNN_SLINKY_AVAILABLE
747+
#ifndef XNN_SLINKY_ENABLED
735748
enum xnn_status xnn_update_runtime_with_threadpool(
736749
xnn_runtime_t runtime,
737750
xnn_threadpool_t threadpool) {
738751
// This operation is not supported.
739752
return xnn_status_deprecated;
740753
}
741-
#endif
754+
#endif // XNN_SLINKY_ENABLED
742755

743756
enum xnn_status xnn_plan_memory(
744757
xnn_runtime_t runtime) {
@@ -787,18 +800,9 @@ enum xnn_status xnn_plan_memory(
787800
return status;
788801
}
789802

790-
enum xnn_status xnn_reshape_runtime(
791-
xnn_runtime_t runtime)
792-
{
803+
enum xnn_status xnn_reshape_runtime(xnn_runtime_t runtime) {
793804
#ifdef XNN_SLINKY_ENABLED
794-
// If compiling with XNN_SLINKY_ENABLED defined, assume we always
795-
// want Slinky enabled, regardless of the runtime flag
796-
const bool use_slinky = true;
797-
#else
798-
const bool use_slinky = (runtime->flags & XNN_FLAG_SLINKY_ENABLED) != 0;
799-
#endif
800-
if (use_slinky) {
801-
#ifdef XNN_SLINKY_AVAILABLE
805+
if (use_slinky(runtime->flags)) {
802806
if (!runtime->slinky_pipeline || (runtime->flags & XNN_FLAG_SLINKY_STATIC_BOUNDS) != 0) {
803807
enum xnn_status status = slinky_init_pipeline(runtime);
804808
if (status != xnn_status_success) {
@@ -807,8 +811,8 @@ enum xnn_status xnn_reshape_runtime(
807811
}
808812
slinky_setup_pipeline(runtime);
809813
return slinky_reshape_pipeline(runtime);
810-
#endif
811814
}
815+
#endif // XNN_SLINKY_ENABLED
812816

813817
bool reallocation_required = false;
814818

@@ -910,12 +914,12 @@ enum xnn_status xnn_setup_runtime(
910914
return status;
911915
}
912916

913-
#ifdef XNN_SLINKY_AVAILABLE
917+
#ifdef XNN_SLINKY_ENABLED
914918
if (runtime->slinky_pipeline) {
915919
// Slinky reshape also performs setup.
916920
return xnn_status_success;
917921
}
918-
#endif
922+
#endif // XNN_SLINKY_ENABLED
919923

920924
return setup_runtime(runtime);
921925
}
@@ -930,12 +934,12 @@ enum xnn_status xnn_setup_runtime_v2(
930934
return status;
931935
}
932936

933-
#ifdef XNN_SLINKY_AVAILABLE
937+
#ifdef XNN_SLINKY_ENABLED
934938
if (runtime->slinky_pipeline) {
935939
slinky_setup_pipeline(runtime);
936940
return xnn_status_success;
937941
}
938-
#endif
942+
#endif // XNN_SLINKY_ENABLED
939943

940944
return setup_runtime(runtime);
941945
}
@@ -1091,11 +1095,11 @@ enum xnn_status xnn_get_runtime_profiling_info(xnn_runtime_t runtime,
10911095
enum xnn_status xnn_invoke_runtime(
10921096
xnn_runtime_t runtime)
10931097
{
1094-
#ifdef XNN_SLINKY_AVAILABLE
1098+
#ifdef XNN_SLINKY_ENABLED
10951099
if (runtime->slinky_pipeline) {
10961100
return slinky_invoke_pipeline(runtime);
10971101
}
1098-
#endif
1102+
#endif // XNN_SLINKY_ENABLED
10991103

11001104
if (runtime->profiling) {
11011105
runtime->start_ts = xnn_read_timer();
@@ -1123,9 +1127,9 @@ enum xnn_status xnn_delete_runtime(
11231127
xnn_runtime_t runtime)
11241128
{
11251129
if (runtime != NULL) {
1126-
#ifdef XNN_SLINKY_AVAILABLE
1130+
#ifdef XNN_SLINKY_ENABLED
11271131
slinky_destroy_pipeline(runtime);
1128-
#endif
1132+
#endif // XNN_SLINKY_ENABLED
11291133

11301134
if (runtime->opdata != NULL) {
11311135
for (size_t i = 0; i < runtime->num_ops; i++) {
@@ -1167,11 +1171,11 @@ enum xnn_status xnn_delete_runtime(
11671171
}
11681172
}
11691173

1170-
#ifdef XNN_SLINKY_AVAILABLE
1174+
#ifdef XNN_SLINKY_ENABLED
11711175
if (runtime->owned_xnn_threadpool != NULL) {
11721176
xnn_delete_threadpool(runtime->owned_xnn_threadpool);
11731177
}
1174-
#endif // XNN_SLINKY_AVAILABLE
1178+
#endif // XNN_SLINKY_ENABLED
11751179

11761180
xnn_release_memory(runtime);
11771181
}

src/subgraph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,8 +2942,8 @@ enum xnn_status xnn_subgraph_optimize(xnn_subgraph_t subgraph,
29422942
}
29432943
#endif
29442944

2945-
#ifdef XNN_SLINKY_ENABLED
2946-
// If compiling with XNN_SLINKY_ENABLED defined, assume we always
2945+
#ifdef XNN_USE_SLINKY
2946+
// If compiling with XNN_USE_SLINKY defined, assume we always
29472947
// want Slinky enabled, regardless of the runtime flag
29482948
const bool use_slinky = true;
29492949
#else

src/xnnpack/subgraph.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
extern "C" {
5555
#endif
5656

57-
#ifdef XNN_SLINKY_AVAILABLE
57+
#ifdef XNN_SLINKY_ENABLED
5858
/// Slinky interface -- unused unless XNN_FLAG_SLINKY_ENABLED is set
5959
struct slinky_pipeline;
6060
typedef struct slinky_pipeline* slinky_pipeline_t;
@@ -64,7 +64,7 @@ void slinky_setup_pipeline(xnn_runtime_t runtime);
6464
void slinky_destroy_pipeline(xnn_runtime_t runtime);
6565
enum xnn_status slinky_reshape_pipeline(xnn_runtime_t runtime);
6666
enum xnn_status slinky_invoke_pipeline(xnn_runtime_t runtime);
67-
#endif // XNN_SLINKY_AVAILABLE
67+
#endif // XNN_SLINKY_ENABLED
6868

6969
struct xnn_shape {
7070
size_t num_dims;
@@ -514,12 +514,12 @@ struct xnn_runtime {
514514
bool has_been_setup;
515515
bool memory_planned;
516516

517-
#ifdef XNN_SLINKY_AVAILABLE
517+
#ifdef XNN_SLINKY_ENABLED
518518
// Fields used by Slinky -- unused unless XNN_FLAG_SLINKY_ENABLED is set
519519
slinky_pipeline_t slinky_pipeline;
520520
xnn_threadpool_t xnn_threadpool;
521521
xnn_threadpool_t owned_xnn_threadpool;
522-
#endif // XNN_SLINKY_AVAILABLE
522+
#endif // XNN_SLINKY_ENABLED
523523
};
524524

525525
enum xnn_status xnn_insert_clamp_node(xnn_subgraph_t subgraph, float output_min,

0 commit comments

Comments
 (0)