GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Fuser/python/python_direct/profile.cpp at main · NVIDIA/Fuser Expand file tree/ Copy pathprofile.cppMore file actions 265 lines (249 loc) · 8.33 KB / Copy pathprofile.cppFile metadata and controls265 lines (249 loc) · 8.33 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 // clang-format off /* * SPDX-FileCopyrightText: Copyright (c) 2025-present NVIDIA CORPORATION & AFFILIATES. * All rights reserved. * SPDX-License-Identifier: BSD-3-Clause */ // clang-format on #include <bindings.h> #include <fusion_profiler.h> namespace nvfuser::python { namespace { void bindFusionProfile(py::module& nvfuser) { py::class_<KernelProfile> kernel_prof( nvfuser, "KernelProfile", py::module_local()); kernel_prof.def("__repr__", [](KernelProfile& self) { std::stringstream ss; ss << self; return ss.str(); }); kernel_prof.def_property_readonly( "name", [](KernelProfile& self) { return self.name; }, R"( Returns the kernel name. )"); kernel_prof.def_property_readonly( "segment_id", [](KernelProfile& self) { return self.segment_id; }, R"( Returns the segment id of the kernel. )"); kernel_prof.def_property_readonly( "device", [](KernelProfile& self) { return self.device; }, R"( Returns the device id where the kernel was executed. )"); kernel_prof.def_property_readonly( "stream", [](KernelProfile& self) { return self.stream; }, R"( Returns the CUDA stream id used for kernel execution. )"); kernel_prof.def_property_readonly( "correlation_id", [](KernelProfile& self) { return self.correlation_id; }, R"( Returns the CUPTI correlation id for the kernel. )"); kernel_prof.def_property_readonly( "compile_time_ms", [](KernelProfile& self) { return self.compile_time_ms; }, R"( Returns the compile time in milliseconds of the kernel. )"); kernel_prof.def_property_readonly( "time_ms", [](KernelProfile& self) { return self.time_ms; }, R"( Returns the execution time in milliseconds of the kernel. )"); kernel_prof.def_property_readonly( "effective_bandwidth_gbs", [](KernelProfile& self) { return self.effective_bandwidth_gbs; }, R"( Returns the effective bandwidth in gigabytes per second of the kernel. )"); kernel_prof.def_property_readonly( "percentage_peak_bandwidth", [](KernelProfile& self) { return self.percentage_peak_bandwidth; }, R"( Returns the percentage of peak bandwidth achieved by the kernel. )"); kernel_prof.def_property_readonly( "grid_str", [](KernelProfile& self) { return self.grid_str; }, R"( Returns the grid dimensions as a string. )"); kernel_prof.def_property_readonly( "block_str", [](KernelProfile& self) { return self.block_str; }, R"( Returns the block dimensions as a string. )"); kernel_prof.def_property_readonly( "cluster_str", [](KernelProfile& self) { return self.cluster_str; }, R"( Returns the cluster dimensions as a string. )"); kernel_prof.def_property_readonly( "shared_mem_str", [](KernelProfile& self) { return self.shared_mem_str; }, R"( Returns the shared memory usage as a string. )"); kernel_prof.def_property_readonly( "registers", [](KernelProfile& self) { return self.registers; }, R"( Returns the number of registers used by the kernel. )"); kernel_prof.def_property_readonly( "input_bytes", [](KernelProfile& self) { return self.input_bytes; }, R"( Returns the input bytes processed by the kernel. )"); kernel_prof.def_property_readonly( "output_bytes", [](KernelProfile& self) { return self.output_bytes; }, R"( Returns the output bytes generated by the kernel. )"); kernel_prof.def_property_readonly( "scheduler", [](KernelProfile& self) { return self.scheduler; }, R"( Returns the scheduler type used for the kernel. )"); py::class_<FusionProfile> fusion_prof( nvfuser, "FusionProfile", py::module_local()); kernel_prof.def("__repr__", [](KernelProfile& self) { std::stringstream ss; ss << self; return ss.str(); }); fusion_prof.def_property_readonly( "verbose", [](FusionProfile& self) { return self.verbose; }, R"( Returns the verbosity of the fusion profile. )"); fusion_prof.def_property_readonly( "fusion_id", [](FusionProfile& self) { return self.fusion_id; }, R"( Returns the fusion id of the fusion profile. )"); fusion_prof.def_property_readonly( "segments", [](FusionProfile& self) { return self.segments; }, R"( Returns the segments in the fusion profile. )"); fusion_prof.def_property_readonly( "cuda_evt_time_ms", [](FusionProfile& self) { return self.cuda_evt_time_ms; }, R"( Returns the CUDA event time in milliseconds of the fusion profile. )"); fusion_prof.def_property_readonly( "host_time_ms", [](FusionProfile& self) { return self.host_time_ms; }, R"( Returns the host time in milliseconds of the fusion profile. )"); fusion_prof.def_property_readonly( "compile_time_ms", [](FusionProfile& self) { return self.compile_time_ms; }, R"( Returns the compile time in milliseconds of the fusion profile. )"); fusion_prof.def_property_readonly( "kernel_time_ms", [](FusionProfile& self) { return self.kernel_time_ms; }, R"( Returns the kernel time in milliseconds of the fusion profile. )"); fusion_prof.def_property_readonly( "effective_bandwidth_gbs", [](FusionProfile& self) { return self.effective_bandwidth_gbs; }, R"( Returns the effective bandwidth in gigabytes per second of the fusion profile. )"); fusion_prof.def_property_readonly( "percentage_peak_bandwith", [](FusionProfile& self) { return self.percentage_peak_bandwidth; }, R"( Returns the percentage of peak bandwidth of the fusion profile. )"); fusion_prof.def_property_readonly( "input_bytes", [](FusionProfile& self) { return self.input_bytes; }, R"( Returns the input bytes of the fusion profile. )"); fusion_prof.def_property_readonly( "output_bytes", [](FusionProfile& self) { return self.output_bytes; }, R"( Returns the output bytes of the fusion profile. )"); fusion_prof.def_property_readonly( "kernel_profiles", [](FusionProfile& self) { return self.kernel_profiles; }, R"( Returns the kernel profiles of the fusion profile. )"); } const FusionProfile& get_fusion_profile() { const FusionProfile& profile = FusionProfiler::profile(); NVF_ERROR( profile.fusion_id != -1, "Something went wrong with Fusion Profiling as an illegal fusion_id " "was returned!") NVF_ERROR( profile.segments > 0, "Something went wrong with Fusion Profiling as no kernel segments were " "profiled!") return profile; } class PythonProfiler { public: PythonProfiler(bool auto_scheduled = false) : auto_scheduled_(auto_scheduled) {} PythonProfiler* start() { ProfilerOptionsGuard::getCurOptions().set(ProfilerOption::Enable); if (!auto_scheduled_) { FusionProfiler::start(); FusionProfiler::createSegments(1); } return this; } void stop() { if (!auto_scheduled_) { FusionProfiler::segment(0).scheduler("user"); FusionProfiler::stop(); } ProfilerOptionsGuard::getCurOptions().unset(ProfilerOption::Enable); } private: //! Automatically scheduled fusions use the FusionExecutorCache. //! The FusionExecutorCache will trigger FusionProfiler, if it is enabled. bool auto_scheduled_ = true; }; void bindProfiler(py::module& nvfuser) { py::class_<PythonProfiler> profiler(nvfuser, "PythonProfiler"); profiler.def(py::init<bool>(), py::arg("auto_scheduled") = true, R"( Create a new PythonProfiler. Parameters ---------- auto_scheduled : bool, optional Whether the fusion is automatically scheduled. )"); profiler.def( "__enter__", &PythonProfiler::start, py::return_value_policy::reference_internal); profiler.def( "__exit__", [&](PythonProfiler& self, py::object exc_type, py::object exc_value, py::object traceback) { self.stop(); }); profiler.def_property_readonly( "profile", [&](PythonProfiler& self) { return get_fusion_profile(); }, py::return_value_policy::reference, R"( Returns the FusionProfile for the profiled fusion. Returns: FusionProfile )"); nvfuser.def( "get_fusion_profile", &get_fusion_profile, py::return_value_policy::reference, R"( Returns the FusionProfile for the profiled fusion. Returns: FusionProfile )"); nvfuser.def( "reset_profiler", &FusionProfiler::reset, R"(Resets FusionProfiler so it can be used again.)"); } } // namespace void bindProfile(py::module& nvfuser) { bindFusionProfile(nvfuser); bindProfiler(nvfuser); } } // namespace nvfuser::python |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |