tilelang.env¶
Attributes¶
, which may lead to compilation bugs when utilize tilelang backend. |
|
, which may lead to compilation bugs when utilize tilelang backend. |
|
, which may lead to compilation bugs when utilize tilelang backend. |
|
Classes¶
Class to manage global kernel caching state. |
|
Descriptor for managing access to a single environment variable. |
|
Environment configuration for TileLang. |
Functions¶
|
Parse a finite, non-negative pass profile threshold in milliseconds. |
|
Resolve pass profile threshold with an explicit pass config taking precedence. |
|
Prepend |
Return CUDA_HOME-derived DLL search directories (Windows only). |
|
Return Windows-only DLL directories shipped with sibling Python packages. |
|
|
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
pathsto%PATH%on Windows, skipping entries already present.Used by Windows DLL discovery: PATH is consulted by
LoadLibraryand byos.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.
- 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:
Centralizing the definition of the variable’s key and default value
Allowing dynamic reads from os.environ so changes take effect immediately
Supporting forced overrides at runtime (for unit tests or debugging)
Logging a warning when a forced value is used (helps detect unexpected overrides)
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
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¶
- enable_cache()¶
- Return type:
None
- disable_cache()¶
- Return type:
None
- 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
- is_running_autodd()¶
Return True if we are running under python -m tilelang.autodd.
- Return type:
- 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,nvccon PATH, pipnvidia-cuda-nvccpackage, or default install paths). This helper expands it into the subdirectories that actually containnvcuda.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_ffiandz3install 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¶