Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ celerybeat-schedule
# Environments
.env
.venv
env/
venv/
env*/
venv*/
ENV/
env.bak/
venv.bak/
Expand Down
3 changes: 2 additions & 1 deletion pytissueoptics/rayscattering/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from .energyLogging import EnergyLogger
from .materials import ScatteringMaterial
from .opencl import CONFIG, hardwareAccelerationIsAvailable
from .opencl import CONFIG, disableOpenCL, hardwareAccelerationIsAvailable
from .photon import Photon
from .scatteringScene import ScatteringScene
from .source import DirectionalSource, DivergentSource, IsotropicPointSource, PencilPointSource
Expand Down Expand Up @@ -49,6 +49,7 @@
"View2DSliceZ",
"samples",
"Stats",
"disableOpenCL",
"hardwareAccelerationIsAvailable",
"CONFIG",
]
13 changes: 12 additions & 1 deletion pytissueoptics/rayscattering/opencl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pytissueoptics.rayscattering.opencl.config.CLConfig import OPENCL_AVAILABLE, WEIGHT_THRESHOLD, CLConfig, warnings
from pytissueoptics.rayscattering.opencl.config.IPPTable import IPPTable
import os

OPENCL_OK = True

Expand All @@ -14,8 +15,17 @@
CONFIG = None


def disableOpenCL():
os.environ["PTO_DISABLE_OPENCL"] = "1"
print("You can define PTO_DISABLE_OPENCL=1 in your profile to avoid this call.")


def validateOpenCL() -> bool:
notAvailableMessage = "Error: Hardware acceleration not available. Falling back to CPU. "

if os.environ.get("PTO_DISABLE_OPENCL", "0") == "1":
warnings.warn("User requested not to use OpenCL with environment variable 'PTO_DISABLE_OPENCL'=1.")
return False
if not OPENCL_AVAILABLE:
warnings.warn(notAvailableMessage + "Please install pyopencl.")
return False
Expand All @@ -28,7 +38,8 @@ def validateOpenCL() -> bool:


def hardwareAccelerationIsAvailable() -> bool:
return OPENCL_AVAILABLE and OPENCL_OK
OPENCL_DISABLED = os.environ.get("PTO_DISABLE_OPENCL", "0") == "1"
return OPENCL_AVAILABLE and OPENCL_OK and not OPENCL_DISABLED


__all__ = ["IPPTable", "WEIGHT_THRESHOLD"]