Feature Gates¶
Feature Gates 是 FBGEMM_GPU 代码库提供的一种机制,它提供了一种在环境设置的基础上启用和禁用实验性功能的一致方法。
虽然可以将其视为对环境变量的类型安全抽象,但请注意,Feature Gates 是一个用于控制代码行为的运行时机制。
创建 Feature Gate¶
如果打算将一项功能合并到代码库中,但要推迟到在生产工作负载中进行进一步验证后再启用,则应创建 Feature Gates。
C++¶
要在 C++ 端定义 Feature Gate,请在 fbgemm_gpu/config/feature_gates.h 中的 ENUMERATE_ALL_FEATURE_FLAGS X 宏定义中添加。
#define ENUMERATE_ALL_FEATURE_FLAGS \
X(...) \
... \
X(EXAMPLE_FEATURE) // <-- Append here
Python¶
要在 Python 端定义 Feature Gate,只需在 fbgemm_gpu/config/feature_list.py 中的 FeatureGateName 枚举定义中添加新值即可。
class FeatureGateName(Enum):
...
# Add here
EXAMPLE_FEATURE = auto()
虽然不是必需的,但为了保持一致性,最好镜像在 fbgemm_gpu/config/feature_gates.h 中定义的枚举值。
启用 Feature Gate¶
有关启用 Feature Gates 的代码示例,请参阅 Feature Gates (C++) 和 Feature Gates (Python) 中的文档。