Skip to content

Commit

Permalink
Added examples for getting started page
Browse files Browse the repository at this point in the history
  • Loading branch information
he11owthere committed Dec 13, 2024
1 parent 9e17d5c commit b3950b0
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@ pip install dyson


```python
from dyson import router
import dyson
import torch
import time
from dyson import router

# Define a function
def mat(a, b):
return torch.matmul(a,b)

class ComplexOperations:
def add(self):
a, b = 1, 3
return a + b

def func(self):
x = torch.tensor([1, 2])
y = torch.tensor([3, 4])
z = torch.add(x, y)
return z
```

### Routing Your Workload
Expand All @@ -37,12 +34,10 @@ Add the `key.cgl` path in your code like so,
key_path = "path/to/your/key.cgl"
```

Add your function with [`paramter`](https://crossgl.github.io/crossgl-docs/dyson/#advanced-routing-parameters) values.
Add your function with [`parameter`](https://crossgl.github.io/crossgl-docs/dyson/#advanced-routing-parameters) values.

```python
physics_function = ComplexOperations()

result = router.route_hardware(
hardware = router.route_hardware(
key_path,
physics_function,
mode="energy-efficient",
Expand All @@ -52,4 +47,19 @@ result = router.route_hardware(
precision="normal",
multi_device=True
)
```
```

We now have the hardware name required for routing. This can be passed as a parameter to the dyson.run() function, enabling it to route to the specified hardware.

```python
# Compile the function for CUDA (or CPU)
func = dyson.run(mat, target_device=hardware)

# Execute the function with arguments
a = torch.randn(1000, 1000)
b = torch.randn(1000, 1000)
result = func(a, b)

print(result)
```

0 comments on commit b3950b0

Please sign in to comment.