Skip to content

Commit

Permalink
Optional use of GPU (plasma-umass#830)
Browse files Browse the repository at this point in the history
* Only init GPU when requested / if it's default on system.

* Suppress a mypy complaint.

* Force init when no GPU is available.

* Bumped version.

* Removed.
  • Loading branch information
emeryberger authored Jul 5, 2024
1 parent 6786a94 commit 8a24e41
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 108 deletions.
2 changes: 1 addition & 1 deletion scalene/find_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def find_browser(browserClass: Optional[str] = None) -> Optional[str]:
# we need to refer to it as such to prevent this error:
# 'MacOSXOSAScript' object has no attribute 'name'
browser = webbrowser.get(browserClass)
return browser._name if browser._name not in text_browsers else None
return browser._name if browser._name not in text_browsers else None # type: ignore[attr-defined]
except webbrowser.Error:
# Return None if there is an error in getting the browser
return None
4 changes: 2 additions & 2 deletions scalene/scalene_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Current version of Scalene; reported by --version."""

scalene_version = "1.5.42.2"
scalene_date = "2024.06.18"
scalene_version = "1.5.42.3"
scalene_date = "2024.07.05"

# Port to use for Scalene UI
SCALENE_PORT = 11235
Expand Down
30 changes: 19 additions & 11 deletions scalene/scalene_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@
if sys.platform != "win32":
import resource

if platform.system() == "Darwin":
from scalene.scalene_apple_gpu import ScaleneAppleGPU as ScaleneGPU
else:
from scalene.scalene_gpu import ScaleneGPU # type: ignore

from scalene.scalene_parseargs import ScaleneParseArgs, StopJupyterExecution
from scalene.scalene_sigqueue import ScaleneSigQueue

Expand Down Expand Up @@ -214,10 +209,7 @@ def last_profiled_tuple() -> Tuple[Filename, LineNumber, ByteCodeIndex]:
__stats = ScaleneStatistics()
__output = ScaleneOutput()
__json = ScaleneJSON()
__gpu = ScaleneGPU()

__output.gpu = __gpu.has_gpu()
__json.gpu = __gpu.has_gpu()
__gpu = None # initialized after parsing arguments in `main`
__invalidate_queue: List[Tuple[Filename, LineNumber]] = []
__invalidate_mutex: threading.Lock
__profiler_base: str
Expand Down Expand Up @@ -762,7 +754,10 @@ def cpu_signal_handler(
)
return

(gpu_load, gpu_mem_used) = Scalene.__gpu.get_stats()
if Scalene.__gpu:
(gpu_load, gpu_mem_used) = Scalene.__gpu.get_stats()
else:
(gpu_load, gpu_mem_used) = (0.0, 0.0)

# Process this CPU sample.
Scalene.process_cpu_sample(
Expand Down Expand Up @@ -1442,7 +1437,7 @@ def after_fork_in_child() -> None:
Scalene.__is_child = True

Scalene.clear_metrics()
if Scalene.__gpu.has_gpu():
if Scalene.__gpu and Scalene.__gpu.has_gpu():
Scalene.__gpu.nvml_reinit()
# Note: __parent_pid of the topmost process is its own pid.
Scalene.__pid = Scalene.__parent_pid
Expand Down Expand Up @@ -1887,6 +1882,19 @@ def main() -> None:
args,
left,
) = ScaleneParseArgs.parse_args()
# Try to profile a GPU if one is found and `--gpu` is selected / it's the default (see ScaleneArguments).
if args.gpu:
if platform.system() == "Darwin":
from scalene.scalene_apple_gpu import ScaleneAppleGPU as ScaleneGPU
else:
from scalene.scalene_gpu import ScaleneGPU # type: ignore
Scalene.__gpu = ScaleneGPU()
Scalene.__output.gpu = Scalene.__gpu.has_gpu()
Scalene.__json.gpu = Scalene.__gpu.has_gpu()
else:
Scalene.__gpu = None
Scalene.__output.gpu = False
Scalene.__json.gpu = False
Scalene.set_initialized()
Scalene.run_profiler(args, left)

Expand Down
94 changes: 0 additions & 94 deletions tests/test_coverup_58.py

This file was deleted.

0 comments on commit 8a24e41

Please sign in to comment.