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

parse_pass_profile_threshold_ms(value[, name])

Parse a finite, non-negative pass profile threshold in milliseconds.

resolve_pass_profile_threshold_ms(pass_configs, key, ...)

Resolve pass profile threshold with an explicit pass config taking precedence.

prepend_dll_search_path(paths)

Prepend paths to %PATH% on Windows, skipping entries already present.

get_cuda_dll_search_dirs()

Return CUDA_HOME-derived DLL search directories (Windows only).

get_windows_runtime_dll_dirs()

Return Windows-only DLL directories shipped with sibling Python packages.

prepend_pythonpath(path)

Module Contents

tilelang.env.logger
tilelang.env.EnvVarDefault
tilelang.env.TargetConfig
tilelang.env.parse_pass_profile_threshold_ms(value, name='pass profile threshold')

Parse a finite, non-negative pass profile threshold in milliseconds.

Parameters:
  • value (object)

  • name (str)

Return type:

float

tilelang.env.resolve_pass_profile_threshold_ms(pass_configs, key, env_threshold_ms)

Resolve pass profile threshold with an explicit pass config taking precedence.

Parameters:
  • pass_configs (collections.abc.Mapping[object, object])

  • key (object)

  • env_threshold_ms (collections.abc.Callable[[], float])

Return type:

float

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
tilelang.env.prepend_dll_search_path(paths)

Prepend paths to %PATH% on Windows, skipping entries already present.

Used by Windows DLL discovery: PATH is consulted by LoadLibrary and by os.add_dll_directory-registered directories alike. POSIX is a no-op.

Parameters:

paths (list[str])

Return type:

None

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.

Return type:

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

Example

```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: EnvVarDefault
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_KERNEL_CACHE_USE_LIB_STAMP
TILELANG_CLEANUP_TEMP_FILES
TILELANG_HIP_SAVE_TEMP_FILES
TILELANG_JIT_DIAGNOSTICS
TILELANG_COMPILE_TIMEOUT_SECONDS
TILELANG_PASS_DIFF
TILELANG_PASS_DIFF_OUTPUT
TL_LOWER_TRACE
TL_LOWER_TRACE_DIR
TILELANG_PASS_PROFILE
TILELANG_PASS_PROFILE_THRESHOLD_MS
TILELANG_ENABLE_IR_SPAN
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()
Return type:

bool

enable_cache()
Return type:

None

disable_cache()
Return type:

None

is_cache_globally_disabled()
Return type:

bool

should_use_kernel_cache_lib_stamp()
Return type:

bool

is_autotune_cache_disabled()
Return type:

bool

is_print_on_compilation_enabled()
Return type:

bool

should_cleanup_temp_files()
Return type:

bool

is_jit_diagnostics_enabled()
Return type:

bool

is_pass_profile_enabled()
Return type:

bool

get_pass_profile_threshold_ms()
Return type:

float

get_compile_timeout_seconds()
Return type:

float | None

get_pass_diff_mode()

Return the pass diff mode: None (off), ‘terminal’, ‘html’, or ‘both’.

Return type:

str | None

get_lower_trace_mode()

Return the lower trace mode: None (off), ‘terminal’, ‘html’, or ‘both’.

Return type:

str | None

get_lower_trace_dir()

Return the base output directory for lower trace artifacts.

Return type:

str

get_default_target()

Get default compilation target from environment.

Return type:

str | TargetConfig

get_default_execution_backend()

Get default execution backend from environment.

Return type:

str

get_default_verbose()

Get default verbose flag from environment.

Return type:

bool

is_running_autodd()

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

Return type:

bool

is_light_import()

Return True if we are running in light import mode.

Return type:

bool

is_span_enable()
Return type:

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.get_cuda_dll_search_dirs()

Return CUDA_HOME-derived DLL search directories (Windows only).

The CUDA_HOME value itself is auto-detected by _find_cuda_home (env vars, nvcc on PATH, pip nvidia-cuda-nvcc package, or default install paths). This helper expands it into the subdirectories that actually contain nvcuda.dll / cudart64_*.dll / nvrtc64_*.dll / nvvm*.dll.

Return type:

list[str]

tilelang.env.get_windows_runtime_dll_dirs()

Return Windows-only DLL directories shipped with sibling Python packages.

Currently locates tvm_ffi and z3 install dirs so their DLLs resolve when TileLang is imported. Each lookup is best-effort; failures are ignored.

Return type:

list[str]

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
tilelang.env.TILELANG_HIP_SAVE_TEMP_FILES