Implementation:InternLM Lmdeploy GetEnv
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Core_Infrastructure |
| Last Updated | 2026-02-07 15:00 GMT |
Overview
Provides a type-safe, cached environment variable reader with automatic type conversion and a macro for declaring environment variable descriptors.
Description
The GetEnv<E>() function template reads an environment variable described by the descriptor type E, caches the result in a static local variable (so it is read only once per program lifetime), and returns the parsed value. The descriptor type E must provide full_name (the actual environment variable name, prefixed with "TM_"), prefix, name, and an init() static method returning the default value. Type conversion is automatic for integral types (via std::stoll), floating-point types (via std::stod), and std::string. The TM_ENV_VAR(prefix, name, init) macro generates the descriptor struct with the naming convention TM_{prefix}_{name}.
Usage
Used throughout TurboMind to read runtime configuration from environment variables. Each configuration point declares a descriptor with TM_ENV_VAR and reads it via GetEnv.
Code Reference
Source Location
- Repository: InternLM_Lmdeploy
- File: src/turbomind/comm/env.h
- Lines: 1-61
Signature
namespace turbomind {
template<class E>
auto GetEnv();
#define TM_ENV_VAR(prefix_, name_, init_) \
struct prefix_##_##name_ { \
static auto init() { return init_; } \
static constexpr auto prefix = #prefix_; \
static constexpr auto name = #name_; \
static constexpr auto full_name = "TM_" #prefix_ "_" #name_; \
}
} // namespace turbomind
Import
#include "src/turbomind/comm/env.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| E (template) | type | Yes | Descriptor struct defining full_name, prefix, name, and init() |
Outputs
| Name | Type | Description |
|---|---|---|
| value | decltype(E::init()) | The parsed environment variable value, or the default from init() |
Usage Examples
#include "src/turbomind/comm/env.h"
using namespace turbomind;
// Declare an environment variable TM_COMM_TIMEOUT with default 5000
TM_ENV_VAR(COMM, TIMEOUT, 5000);
// Read it (cached after first call)
int timeout = GetEnv<COMM_TIMEOUT>();