1 //////////////////////////////////////////////////////////////////////////////// 2 // 3 // The University of Illinois/NCSA 4 // Open Source License (NCSA) 5 // 6 // Copyright (c) 2014-2015, Advanced Micro Devices, Inc. All rights reserved. 7 // 8 // Developed by: 9 // 10 // AMD Research and AMD HSA Software Development 11 // 12 // Advanced Micro Devices, Inc. 13 // 14 // www.amd.com 15 // 16 // Permission is hereby granted, free of charge, to any person obtaining a copy 17 // of this software and associated documentation files (the "Software"), to 18 // deal with the Software without restriction, including without limitation 19 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 20 // and/or sell copies of the Software, and to permit persons to whom the 21 // Software is furnished to do so, subject to the following conditions: 22 // 23 // - Redistributions of source code must retain the above copyright notice, 24 // this list of conditions and the following disclaimers. 25 // - Redistributions in binary form must reproduce the above copyright 26 // notice, this list of conditions and the following disclaimers in 27 // the documentation and/or other materials provided with the distribution. 28 // - Neither the names of Advanced Micro Devices, Inc, 29 // nor the names of its contributors may be used to endorse or promote 30 // products derived from this Software without specific prior written 31 // permission. 32 // 33 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIESd OF MERCHANTABILITY, 35 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 36 // THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 37 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 38 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 39 // DEALINGS WITH THE SOFTWARE. 40 // 41 //////////////////////////////////////////////////////////////////////////////// 42 43 #ifndef HSA_RUNTIME_CORE_INC_FLAG_H_ 44 #define HSA_RUNTIME_CORE_INC_FLAG_H_ 45 46 #include <stdint.h> 47 48 #include <string> 49 50 #include "core/util/os.h" 51 #include "core/util/utils.h" 52 53 class Flag { 54 public: Flag()55 explicit Flag() { Refresh(); } 56 ~Flag()57 virtual ~Flag() {} 58 Refresh()59 void Refresh() { 60 std::string var = os::GetEnvVar("HSA_CHECK_FLAT_SCRATCH"); 61 check_flat_scratch_ = (var == "1") ? true : false; 62 63 var = os::GetEnvVar("HSA_ENABLE_VM_FAULT_MESSAGE"); 64 enable_vm_fault_message_ = (var == "0") ? false : true; 65 66 var = os::GetEnvVar("HSA_ENABLE_QUEUE_FAULT_MESSAGE"); 67 enable_queue_fault_message_ = (var == "0") ? false : true; 68 69 var = os::GetEnvVar("HSA_ENABLE_INTERRUPT"); 70 enable_interrupt_ = (var == "0") ? false : true; 71 72 enable_sdma_ = os::GetEnvVar("HSA_ENABLE_SDMA"); 73 74 var = os::GetEnvVar("HSA_RUNNING_UNDER_VALGRIND"); 75 running_valgrind_ = (var == "1") ? true : false; 76 77 var = os::GetEnvVar("HSA_SDMA_WAIT_IDLE"); 78 sdma_wait_idle_ = (var == "1") ? true : false; 79 80 var = os::GetEnvVar("HSA_MAX_QUEUES"); 81 max_queues_ = static_cast<uint32_t>(atoi(var.c_str())); 82 83 var = os::GetEnvVar("HSA_SCRATCH_MEM"); 84 scratch_mem_size_ = atoi(var.c_str()); 85 86 tools_lib_names_ = os::GetEnvVar("HSA_TOOLS_LIB"); 87 88 var = os::GetEnvVar("HSA_TOOLS_REPORT_LOAD_FAILURE"); 89 #ifdef NDEBUG 90 report_tool_load_failures_ = (var == "1") ? true : false; 91 #else 92 report_tool_load_failures_ = (var == "0") ? false : true; 93 #endif 94 95 var = os::GetEnvVar("HSA_DISABLE_FRAGMENT_ALLOCATOR"); 96 disable_fragment_alloc_ = (var == "1") ? true : false; 97 98 var = os::GetEnvVar("HSA_ENABLE_SDMA_HDP_FLUSH"); 99 enable_sdma_hdp_flush_ = (var == "0") ? false : true; 100 } 101 check_flat_scratch()102 bool check_flat_scratch() const { return check_flat_scratch_; } 103 enable_vm_fault_message()104 bool enable_vm_fault_message() const { return enable_vm_fault_message_; } 105 enable_queue_fault_message()106 bool enable_queue_fault_message() const { return enable_queue_fault_message_; } 107 enable_interrupt()108 bool enable_interrupt() const { return enable_interrupt_; } 109 enable_sdma_hdp_flush()110 bool enable_sdma_hdp_flush() const { return enable_sdma_hdp_flush_; } 111 running_valgrind()112 bool running_valgrind() const { return running_valgrind_; } 113 sdma_wait_idle()114 bool sdma_wait_idle() const { return sdma_wait_idle_; } 115 report_tool_load_failures()116 bool report_tool_load_failures() const { return report_tool_load_failures_; } 117 disable_fragment_alloc()118 bool disable_fragment_alloc() const { return disable_fragment_alloc_; } 119 enable_sdma()120 std::string enable_sdma() const { return enable_sdma_; } 121 max_queues()122 uint32_t max_queues() const { return max_queues_; } 123 scratch_mem_size()124 size_t scratch_mem_size() const { return scratch_mem_size_; } 125 tools_lib_names()126 std::string tools_lib_names() const { return tools_lib_names_; } 127 128 private: 129 bool check_flat_scratch_; 130 bool enable_vm_fault_message_; 131 bool enable_interrupt_; 132 bool enable_sdma_hdp_flush_; 133 bool running_valgrind_; 134 bool sdma_wait_idle_; 135 bool enable_queue_fault_message_; 136 bool report_tool_load_failures_; 137 bool disable_fragment_alloc_; 138 139 std::string enable_sdma_; 140 141 uint32_t max_queues_; 142 143 size_t scratch_mem_size_; 144 145 std::string tools_lib_names_; 146 147 DISALLOW_COPY_AND_ASSIGN(Flag); 148 }; 149 150 #endif // header guard 151