|
| 1 | +// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +// Part of the following code in this file is from |
| 16 | +// https://github.com/google/glog/blob/master/src/base/commandlineflags.h |
| 17 | +// Git commit hash: 9f0b7d3bfe1542848f784e8d1c545b916cec6b3e |
| 18 | +// Retain the following license from the original files: |
| 19 | + |
| 20 | +// Copyright (c) 2008, Google Inc. |
| 21 | +// All rights reserved. |
| 22 | +// |
| 23 | +// Redistribution and use in source and binary forms, with or without |
| 24 | +// modification, are permitted provided that the following conditions are |
| 25 | +// met: |
| 26 | +// |
| 27 | +// * Redistributions of source code must retain the above copyright |
| 28 | +// notice, this list of conditions and the following disclaimer. |
| 29 | +// * Redistributions in binary form must reproduce the above |
| 30 | +// copyright notice, this list of conditions and the following disclaimer |
| 31 | +// in the documentation and/or other materials provided with the |
| 32 | +// distribution. |
| 33 | +// * Neither the name of Google Inc. nor the names of its |
| 34 | +// contributors may be used to endorse or promote products derived from |
| 35 | +// this software without specific prior written permission. |
| 36 | +// |
| 37 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 38 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 39 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 40 | +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 41 | +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 42 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 43 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 44 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 45 | +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 46 | +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 47 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 48 | + |
| 49 | +#ifndef BACKENDS_MLU_RUNTIME_FLAGS_H_ |
| 50 | +#define BACKENDS_MLU_RUNTIME_FLAGS_H_ |
| 51 | + |
| 52 | +#include "gflags/gflags.h" |
| 53 | + |
| 54 | +#define FLAGS_DEFINE_bool(name, value, meaning) \ |
| 55 | + DEFINE_bool(name, EnvToBool("FLAGS_" #name, value), meaning) |
| 56 | + |
| 57 | +#define FLAGS_DEFINE_int32(name, value, meaning) \ |
| 58 | + DEFINE_int32(name, EnvToInt("FLAGS_" #name, value), meaning) |
| 59 | + |
| 60 | +#define FLAGS_DEFINE_uint32(name, value, meaning) \ |
| 61 | + DEFINE_uint32(name, EnvToUInt("FLAGS_" #name, value), meaning) |
| 62 | + |
| 63 | +#define FLAGS_DEFINE_uint64(name, value, meaning) \ |
| 64 | + DEFINE_uint64(name, EnvToUInt("FLAGS_" #name, value), meaning) |
| 65 | + |
| 66 | +#define FLAGS_DEFINE_string(name, value, meaning) \ |
| 67 | + DEFINE_string(name, EnvToString("FLAGS_" #name, value), meaning) |
| 68 | + |
| 69 | +#define EnvToString(envname, dflt) (!getenv(envname) ? (dflt) : getenv(envname)) |
| 70 | + |
| 71 | +#define EnvToBool(envname, dflt) \ |
| 72 | + (!getenv(envname) ? (dflt) : memchr("tTyY1\0", getenv(envname)[0], 6) != NULL) |
| 73 | + |
| 74 | +#define EnvToInt(envname, dflt) \ |
| 75 | + (!getenv(envname) ? (dflt) : strtol(getenv(envname), NULL, 10)) |
| 76 | + |
| 77 | +#define EnvToUInt(envname, dflt) \ |
| 78 | + (!getenv(envname) ? (dflt) : strtoul(getenv(envname), NULL, 10)) |
| 79 | + |
| 80 | +#endif // BACKENDS_MLU_RUNTIME_FLAGS_H_ |
0 commit comments