Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ enum xnn_status xnn_update_runtime_with_threadpool(
xnn_runtime_t runtime,
xnn_threadpool_t threadpool);


typedef struct xnn_config_identifier {
uint64_t identifier;
} xnn_config_identifier;

/// Check whether the given configuration matches one that is currently in use.
///
/// @returns True if the configuration matches.
bool xnn_check_config_version(const struct xnn_config_identifier* identifier);

/// Returns a valid microkernel configuration.
///
/// This is useful for consumers of this API that want to test their checks
/// against kernel configurations.
const struct xnn_config_identifier* xnn_get_test_config();


#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
5 changes: 5 additions & 0 deletions include/xnnpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,11 @@ struct xnn_weights_cache_look_up_key {
const void* kernel;
/// Pointer to the original bias, could be NULL.
const void* bias;
/// Pointer to the operation configuration, can be NULL.
///
/// If this is set, then the cache is allowed to compare the configuration to
/// previous runs and maybe reuse those run results.
const struct xnn_config_identifier* config;
};

/// A group of function pointers to manage weights cache. All functions may be
Expand Down
1 change: 1 addition & 0 deletions src/configs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ xnnpack_cc_library(
"avgpool-config.c",
"binary-elementwise-config.c",
"cmul-config.c",
"config-identifier.c",
"conv-hwc2chw-config.c",
"dwconv-config.c",
"dwconv2d-chw-config.c",
Expand Down
79 changes: 79 additions & 0 deletions src/configs/config-identifier.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2025 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include "include/experimental.h"
#include "src/xnnpack/config-types.h"
#include "src/xnnpack/config.h"

xnn_config_identifier xnn_create_config_identifier(xnn_config_name name,
uint32_t version) {
struct xnn_config_identifier id = {((uint64_t)name) << 32 | version};
return id;
}

xnn_config_name xnn_get_config_name(const xnn_config_identifier* identifier) {
return identifier->identifier >> 32;
}

xnn_config_name xnn_get_config_version(
const xnn_config_identifier* identifier) {
return identifier->identifier & 0xffffffff;
}

const xnn_config_identifier* xnn_get_test_config() {
const struct xnn_gemm_config* f32_config =
xnn_init_f32_gemm_config(/*flags=*/0);
return &(f32_config->identifier);
}

#define XNNPACK_CHECK_CONFIG(CONFIG_NAME, ...) \
if (config_name == xnn_config_name_##CONFIG_NAME) { \
const struct xnn_gemm_config* kernel_config = \
xnn_init_##CONFIG_NAME##_config(__VA_ARGS__); \
return kernel_config && \
identifier->identifier == kernel_config->identifier.identifier; \
}

bool xnn_check_config_version(const xnn_config_identifier* identifier) {
if (identifier == NULL) {
return false;
}
const xnn_config_name config_name = xnn_get_config_name(identifier);
XNNPACK_CHECK_CONFIG(bf16_f32_gemm);
XNNPACK_CHECK_CONFIG(f16_gemm);
XNNPACK_CHECK_CONFIG(f32_gemm, /*flags=*/0);
XNNPACK_CHECK_CONFIG(f32_gemm_nr2, /*flags=*/0);
XNNPACK_CHECK_CONFIG(f32_igemm);
XNNPACK_CHECK_CONFIG(f32_qc8w_gemm);
XNNPACK_CHECK_CONFIG(f32_qc4w_gemm);
XNNPACK_CHECK_CONFIG(pf16_gemm);
XNNPACK_CHECK_CONFIG(pf32_gemm);
XNNPACK_CHECK_CONFIG(pqs8_qc8w_gemm);
XNNPACK_CHECK_CONFIG(qd8_f16_qb4w_gemm);
XNNPACK_CHECK_CONFIG(qd8_f16_qc4w_gemm);
XNNPACK_CHECK_CONFIG(qd8_f16_qc8w_gemm);
XNNPACK_CHECK_CONFIG(qd8_f16_qc8w_igemm);
XNNPACK_CHECK_CONFIG(qd8_f32_qb4w_gemm);
XNNPACK_CHECK_CONFIG(qd8_f32_qc4w_gemm);
XNNPACK_CHECK_CONFIG(qd8_f32_qc8w_gemm);
XNNPACK_CHECK_CONFIG(qp8_f32_qc4w_gemm);
XNNPACK_CHECK_CONFIG(qp8_f32_qc8w_gemm);
XNNPACK_CHECK_CONFIG(qp8_f32_qb4w_gemm);
XNNPACK_CHECK_CONFIG(qdu8_f32_qc4w_gemm);
XNNPACK_CHECK_CONFIG(qdu8_f16_qc8w_gemm);
XNNPACK_CHECK_CONFIG(qdu8_f32_qc8w_gemm);
XNNPACK_CHECK_CONFIG(qdu8_f32_qb4w_gemm);
XNNPACK_CHECK_CONFIG(qdu8_f16_qc4w_gemm);
XNNPACK_CHECK_CONFIG(qdu8_f32_qc8w_igemm);
XNNPACK_CHECK_CONFIG(qs8_qc4w_gemm);
XNNPACK_CHECK_CONFIG(qs8_qc8w_gemm);
XNNPACK_CHECK_CONFIG(qu8_gemm);
return false;
}
Loading
Loading