Skip to content

Commit

Permalink
Update setup example to use cupy
Browse files Browse the repository at this point in the history
  • Loading branch information
olsaarik authored and Saeed Maleki committed Nov 8, 2023
1 parent 2513eea commit e0d1c4a
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions docs/setup_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"import mscclpp\n",
"import torch\n",
"\n",
"def setup_channels(comm, memory, proxy_service):\n",
" # Register the memory with the communicator\n",
" ptr = memory.data_ptr()\n",
" size = memory.numel() * memory.element_size()\n",
" reg_mem = comm.register_memory(ptr, size, mscclpp.Transport.CudaIpc)\n",
" reg_mem = comm.register_memory(memory.data.ptr, memory.nbytes, mscclpp.Transport.CudaIpc)\n",
"\n",
" # Create connections to all other ranks and exchange registered memories\n",
" connections = []\n",
Expand Down Expand Up @@ -60,17 +57,18 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"import cupy as cp\n",
"\n",
"def run(rank, world_size, if_ip_port_trio):\n",
" # Use the right GPU for this rank\n",
" torch.cuda.set_device(rank)\n",
" cp.cuda.Device(rank).use()\n",
" \n",
" # Allocate memory on the GPU\n",
" memory = torch.zeros(1024, dtype=torch.int32)\n",
" memory = memory.to(\"cuda\")\n",
" memory = cp.zeros(1024, dtype=cp.int32)\n",
"\n",
" # Initialize a bootstrapper using a known interface/IP/port trio for the root rank\n",
" boot = mscclpp.TcpBootstrap.create(rank, world_size)\n",
Expand Down Expand Up @@ -109,7 +107,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -155,7 +153,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.11.5"
},
"orig_nbformat": 4
},
Expand Down

0 comments on commit e0d1c4a

Please sign in to comment.