tilelang.env

Attributes

Classes

CacheState

Class to manage global kernel caching state.

EnvVar

Descriptor for managing access to a single environment variable.

Environment

Environment configuration for TileLang.

Functions

Module Contents

tilelang.env.logger
tilelang.env.CUTLASS_NOT_FOUND_MESSAGE = 'CUTLASS is not installed or found in the expected path'

, which may lead to compilation bugs when utilize tilelang backend.

tilelang.env.COMPOSABLE_KERNEL_NOT_FOUND_MESSAGE = 'Composable Kernel is not installed or found in the expected path'

, which may lead to compilation bugs when utilize tilelang backend.

tilelang.env.TL_TEMPLATE_NOT_FOUND_MESSAGE = 'TileLang is not installed or found in the expected path'

, which may lead to compilation bugs when utilize tilelang backend.

tilelang.env.TVM_LIBRARY_NOT_FOUND_MESSAGE = 'TVM is not installed or found in the expected path'
tilelang.env.TL_ROOT
tilelang.env.TL_LIBS
tilelang.env.TL_LIBS
tilelang.env.DEV = False
tilelang.env.THIRD_PARTY_ROOT
tilelang.env.DEV = True
class tilelang.env.CacheState

Class to manage global kernel caching state.

classmethod enable()

Enable kernel caching globally.

classmethod disable()

Disable kernel caching globally.

classmethod is_enabled()

Return current cache state.

返回类型:

bool

class tilelang.env.EnvVar

Descriptor for managing access to a single environment variable.

Purpose

In many projects, access to environment variables is scattered across the codebase:
  • os.environ.get(...) calls are repeated everywhere

  • Default values are hard-coded in multiple places

  • Overriding env vars for tests/debugging is messy

  • There's no central place to see all environment variables a package uses

This descriptor solves those issues by:
  1. Centralizing the definition of the variable's key and default value

  2. Allowing dynamic reads from os.environ so changes take effect immediately

  3. Supporting forced overrides at runtime (for unit tests or debugging)

  4. Logging a warning when a forced value is used (helps detect unexpected overrides)

  5. Optionally syncing forced values back to os.environ if global consistency is desired

How it works

  • This is a dataclass implementing the descriptor protocol (__get__, __set__)

  • When used as a class attribute, instance.attr triggers __get__()

    → returns either the forced override or the live value from os.environ

  • Assigning to the attribute (instance.attr = value) triggers __set__()

    → stores _forced_value for future reads

  • You may uncomment the os.environ[...] = value line in __set__ if you want the override to persist globally in the process

示例

```python class Environment:

TILELANG_PRINT_ON_COMPILATION = EnvVar("TILELANG_PRINT_ON_COMPILATION", "0")

env = Environment() print(cfg.TILELANG_PRINT_ON_COMPILATION) # Reads from os.environ (with default fallback) cfg.TILELANG_PRINT_ON_COMPILATION = "1" # Forces value to "1" until changed/reset ```

Benefits

  • Centralizes all env-var keys and defaults in one place

  • Live, up-to-date reads (no stale values after import)

  • Testing convenience (override without touching the real env)

  • Improves IDE discoverability and type hints

  • Avoids hardcoding os.environ.get(...) in multiple places

key: str
default: str
get()
__get__(instance, owner)

Called when the attribute is accessed. 1. If a forced value is set, return it and log a warning 2. Otherwise, look up the value in os.environ; return the default if missing

__set__(instance, value)

Called when the attribute is assigned to. Stores the value as a runtime override (forced value). Optionally, you can also sync this into os.environ for global effect.

class tilelang.env.Environment

Environment configuration for TileLang. Handles CUDA/ROCm detection, integration paths, template/cache locations, auto-tuning configs, and build options.

CUDA_HOME
ROCM_HOME
TILELANG_PACKAGE_PATH
CUTLASS_INCLUDE_DIR
COMPOSABLE_KERNEL_INCLUDE_DIR
TVM_PYTHON_PATH
TVM_LIBRARY_PATH
TILELANG_TEMPLATE_PATH
TILELANG_CACHE_DIR
TILELANG_TMP_DIR
TILELANG_PRINT_ON_COMPILATION
TILELANG_DISABLE_CACHE
TILELANG_CLEAR_CACHE
TILELANG_USE_GEMM_V1
TILELANG_AUTO_TUNING_DISABLE_CACHE
TILELANG_AUTO_TUNING_CPU_UTILITIES
TILELANG_AUTO_TUNING_CPU_COUNTS
TILELANG_AUTO_TUNING_MAX_CPU_COUNT
TILELANG_DEFAULT_TARGET
TILELANG_DEFAULT_EXECUTION_BACKEND
TILELANG_DEFAULT_VERBOSE
SKIP_LOADING_TILELANG_SO
TVM_IMPORT_PYTHON_PATH
is_cache_enabled()
返回类型:

bool

enable_cache()
返回类型:

None

disable_cache()
返回类型:

None

is_cache_globally_disabled()
返回类型:

bool

is_autotune_cache_disabled()
返回类型:

bool

is_print_on_compilation_enabled()
返回类型:

bool

use_gemm_v1()

Return True if GEMM v1 should be used based on env.

Controlled by TILELANG_USE_GEMM_V1. Truthy values are one of {"1", "true", "yes", "on"} (case-insensitive).

返回类型:

bool

get_default_target()

Get default compilation target from environment.

返回类型:

str

get_default_execution_backend()

Get default execution backend from environment.

返回类型:

str

get_default_verbose()

Get default verbose flag from environment.

返回类型:

bool

is_running_autodd()

Return True if we are running under python -m tilelang.autodd.

返回类型:

bool

is_light_import()

Return True if we are running in light import mode.

返回类型:

bool

tilelang.env.env
tilelang.env.enable_cache
tilelang.env.disable_cache
tilelang.env.is_cache_enabled
tilelang.env.CUDA_HOME
tilelang.env.ROCM_HOME
tilelang.env.prepend_pythonpath(path)
tilelang.env.tvm_path
tilelang.env.cutlass_inc_path
tilelang.env.ck_inc_path
tilelang.env.tl_template_path
tilelang.env.CUTLASS_INCLUDE_DIR
tilelang.env.COMPOSABLE_KERNEL_INCLUDE_DIR
tilelang.env.TILELANG_TEMPLATE_PATH