Söker efter resursstöd för aktivitetskoordinator
Det här exemplet visar hur appar kan använda IsActivityCoordinatorResourceSupported för att identifiera stöd för resurser innan de skapar en princip. Du kan använda IsActivityCoordinatorResourceSupported
för att kontrollera eventuella ACTIVITY_COORDINATOR_RESOURCE som stöds vid körning.
Sök efter exempel på NPU-support
I följande exempel visas hur du söker efter NPU-stöd med hjälp av det nya API:et för funktionskontroll för resurser. Med det här API:et kan appar söka efter resurstyper som stöds vid körning och returnerar true
om NPU-resursen stöds i det aktuella systemet. I det här exemplet skapas en policy för aktivitetskoordinator och NPU-resursvillkoret anges till ACTIVITY_COORDINATOR_CONDITION_GOOD
om det stöds.
#include <Windows.h>
#include <ActivityCoordinator.h>
#include <wil/resource.h>
#include <apiquery2.h>
// Declare RAII wrappers for the Activity Coordinator policy and subscription.
// These behave like traditional smart pointers and will call their associated
// API cleanup functions when they go out of scope.
using unique_policy = wil::unique_any<
ACTIVITY_COORDINATOR_POLICY,
decltype(&DestroyActivityCoordinatorPolicy),
DestroyActivityCoordinatorPolicy>;
bool
CanUseNpuPolicy()
{
// Check that the Activity Coordinator feature check API is implemented
// before calling.
if (IsApiSetImplemented("ext-ms-win-resourcemanager-activitycoordinator-l1-1-1")) {
if (IsActivityCoordinatorResourceSupported(ACTIVITY_COORDINATOR_RESOURCE_NPU)) {
return true;
}
}
return false;
}
int
__cdecl
wmain()
{
unique_policy policy;
// Activity Coordinator support for NPUs does not indicate their actual
// presence on the system. Applications must still detect and target desired
// hardware using their API or framework of choice.
//
// When using system resources not supported by Activity Coordinator, it is
// recommended that policies always include USER_IDLE in the GOOD condition.
// This will help minimize the potential for interference with a user's
// foreground applications utilizing the same resource.
//
// The GOOD policy template covers this scenario in addition to other
// resources that most applications are likely to affect even when targeting
// dedicated hardware.
RETURN_IF_FAILED(CreateActivityCoordinatorPolicy(
ACTIVITY_COORDINATOR_POLICY_TEMPLATE_GOOD,
&policy));
if (CanUseNpuPolicy()) {
RETURN_IF_FAILED(SetActivityCoordinatorPolicyResourceCondition(
policy.get(),
ACTIVITY_COORDINATOR_RESOURCE_NPU,
ACTIVITY_COORDINATOR_CONDITION_GOOD));
}
// Proceed to use Activity Coordinator to run opportunistic work. See the
// example project in the documentation for further details.
return S_OK;
}