fix send to other devices and compile on cloud

This commit is contained in:
lucasdelimanogueira 2024-05-29 17:48:37 -03:00
parent 446b382333
commit 38a860eba1
4 changed files with 22 additions and 17 deletions

View file

@ -15,11 +15,9 @@ $ pip install norch
or from cloning this repository
```css
$ sudo apt install nvidia-cuda-toolkit
$ git clone https://github.com/lucasdelimanogueira/PyNorch.git
$ cd build
$ make
$ cd ..
$ cd PyNorch
$ pip install . -v
```
# 3 - Get started
@ -66,7 +64,7 @@ class MyModel(nn.Module):
```python
import norch
from norch.utils.data.dataloader import DataLoader
from norch.norchvision import transforms
from norch.norchvision import transforms as T
import norch
import norch.nn as nn
import norch.optim as optim
@ -77,16 +75,16 @@ BATCH_SIZE = 32
device = "cuda" #cpu
epochs = 10
transform = transforms.Compose(
transform = T.Compose(
[
transforms.ToTensor(),
transforms.Reshape([-1, 784, 1])
T.ToTensor(),
T.Reshape([-1, 784, 1])
]
)
target_transform = transforms.Compose(
target_transform = T.Compose(
[
transforms.ToTensor()
T.ToTensor()
]
)

View file

@ -13,7 +13,7 @@ CUDAFLAGS = -arch=sm_75
CUDALIBS = -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lcudart -lcuda
# MPI flags and libraries
DISTRIBUTEDLIBS = -lmpi_cxx -lnccl
DISTRIBUTEDLIBS = -lmpi_cxx -lnccl -lmpi
# Directories
SRCDIR = ../norch/csrc

View file

@ -34,7 +34,7 @@
"import norch.nn as nn\n",
"import norch.optim as optim\n",
"from norch.utils.data.dataloader import DataLoader\n",
"from norch.norchvision import transforms\n",
"from norch.norchvision import transforms as T\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import random\n",
@ -102,16 +102,16 @@
"device = \"cuda\" #cpu\n",
"epochs = 10\n",
"\n",
"transform = transforms.Compose(\n",
"transform = T.Compose(\n",
" [\n",
" transforms.ToTensor(),\n",
" transforms.Reshape([-1, 784, 1])\n",
" T.ToTensor(),\n",
" T.Reshape([-1, 784, 1])\n",
" ]\n",
")\n",
"\n",
"target_transform = transforms.Sequential(\n",
"target_transform = T.Compose(\n",
" [\n",
" transforms.ToTensor()\n",
" T.ToTensor()\n",
" ]\n",
")\n",
"\n",

View file

@ -66,9 +66,12 @@ extern "C" {
void to_device(Tensor* tensor, char* target_device) {
int device_id = 0;
char* endptr;
long num = strtol(target_device, &endptr, 10);
if (*endptr == '\0') {
device_id = (int)num;
target_device = new char[strlen("cuda") + 1];
strcpy(target_device, "cuda");
}
if ((strcmp(target_device, "cuda") == 0) && (strcmp(tensor->device, "cpu") == 0)) {
@ -78,6 +81,10 @@ extern "C" {
else if ((strcmp(target_device, "cpu") == 0) && (strcmp(tensor->device, "cuda") == 0)) {
cuda_to_cpu(tensor);
}
else {
printf("Could not send tensor to device %d", device_id);
}
}
Tensor* add_tensor(Tensor* tensor1, Tensor* tensor2) {