Skip to content

Commit

Permalink
renaming device type setter
Browse files Browse the repository at this point in the history
  • Loading branch information
viclafargue committed Feb 3, 2023
1 parent f3d4900 commit a40befe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 21 additions & 13 deletions docs/source/execution_device_interoperability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 1,
"source": [
"import pickle\n",
"import cuml\n",
"from cuml.common.device_selection import using_device_type\n",
"from cuml.common.device_selection import set_global_device_type, get_current_device_type\n",
"from cuml.common.device_selection import set_global_device_type, get_global_device_type\n",
"from cuml.neighbors import NearestNeighbors\n",
"from cuml.manifold import UMAP\n",
"from cuml.linear_model import LinearRegression\n",
Expand All @@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 2,
"source": [
"nn = NearestNeighbors()\n",
"with using_device_type('cpu'):\n",
Expand All @@ -60,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 3,
"source": [
"umap_model = UMAP(angular_rp_forest=True) # `angular_rp_forest` hyperparameter only available in UMAP library\n",
"with using_device_type('cpu'):\n",
Expand All @@ -73,7 +73,15 @@
"output_type": "stream",
"name": "stdout",
"text": [
"[I] [16:40:12.572459] Unused keyword parameter: angular_rp_forest during cuML estimator initialization\n"
"[I] [14:46:20.500110] Unused keyword parameter: angular_rp_forest during cuML estimator initialization\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"/home/vic/mambaforge/envs/all_cuda-115_arch-x86_64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
Expand All @@ -90,7 +98,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 4,
"source": [
"lin_reg = LinearRegression()\n",
"with using_device_type('gpu'):\n",
Expand All @@ -111,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 5,
"source": [
"recovered_lin_reg = pickle.load(open(\"lin_reg.pkl\", \"rb\"))\n",
"with using_device_type('cpu'):\n",
Expand All @@ -129,9 +137,9 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 6,
"source": [
"initial_device_type = get_current_device_type()\n",
"initial_device_type = get_global_device_type()\n",
"print('default execution device:', initial_device_type)"
],
"outputs": [
Expand All @@ -154,11 +162,11 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 7,
"source": [
"for param in ['cpu', 'host', 'gpu', 'device']:\n",
" with using_device_type(param):\n",
" print('using_device_type({}):'.format(param), get_current_device_type())"
" print('using_device_type({}):'.format(param), get_global_device_type())"
],
"outputs": [
{
Expand All @@ -183,10 +191,10 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 8,
"source": [
"set_global_device_type('gpu')\n",
"print('new device type:', get_current_device_type())"
"print('new device type:', get_global_device_type())"
],
"outputs": [
{
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/common/device_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def set_global_device_type(device_type):
GlobalSettings().device_type = DeviceType.from_str(device_type)


def get_current_device_type():
def get_global_device_type():
return GlobalSettings().device_type


Expand Down

0 comments on commit a40befe

Please sign in to comment.