tvm
Loading...
Searching...
No Matches
env.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
24#ifndef TVM_SUPPORT_ENV_H_
25#define TVM_SUPPORT_ENV_H_
26
27#include <cstdlib>
28#include <sstream>
29#include <string>
30#include <type_traits>
31
32namespace tvm {
33namespace support {
34
42template <typename T>
43inline T GetEnv(const char* key, T default_value) {
44 const char* val = std::getenv(key);
45 if (val == nullptr || !*val) return default_value;
46 if constexpr (std::is_same_v<T, std::string>) {
47 return std::string(val);
48 } else if constexpr (std::is_same_v<T, bool>) {
49 // Accept "0"/"false" as false, anything else as true
50 std::string s(val);
51 return !(s == "0" || s == "false" || s == "False" || s == "FALSE");
52 } else {
53 T ret;
54 std::istringstream is(val);
55 is >> ret;
56 return ret;
57 }
58}
59
60} // namespace support
61} // namespace tvm
62
63#endif // TVM_SUPPORT_ENV_H_
T GetEnv(const char *key, T default_value)
Get environment variable with a typed default value.
Definition env.h:43
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23