From 35c028dbeb062db8feb3b0dbcd14b0a1cef30475 Mon Sep 17 00:00:00 2001 From: lucasdelimanogueira Date: Mon, 29 Apr 2024 12:50:48 -0300 Subject: [PATCH] Makefile cuda --- build/Makefile | 2 +- csrc/tensor.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/build/Makefile b/build/Makefile index 9d38c99..cf3c755 100644 --- a/build/Makefile +++ b/build/Makefile @@ -19,7 +19,7 @@ CU_OBJS = $(patsubst $(SRCDIR)/%.cu, $(BUILDDIR)/%.cu.o, $(CU_SRCS)) # CUDA flags and libraries CUDAFLAGS = -arch=sm_75 -CUDALIBS = -lcudart +CUDALIBS = -L/usr/local/cuda-10.2/lib64/ -lcudart -lcuda # Rule to build the target $(TARGET): $(OBJS) $(CU_OBJS) diff --git a/csrc/tensor.cpp b/csrc/tensor.cpp index 7bf0005..6e2e336 100644 --- a/csrc/tensor.cpp +++ b/csrc/tensor.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "tensor.h" #include "cuda.h" #define THREADS_PER_BLOCK 128 @@ -76,14 +77,15 @@ extern "C" { void to_device(Tensor* tensor, char* device) { printf("Sending tensor to device: %s\n", device); #ifdef __CUDACC__ + if ((strcmp(device, "cuda") == 0) && (strcmp(tensor->device, "cpu") == 0)) { - + float* data_tmp; cudaMalloc((void **)&data_tmp, tensor->size * sizeof(float)); cudaMemcpy(data_tmp, tensor->data, tensor->size * sizeof(float), cudaMemcpyHostToDevice); - free(tensor_data); + free(tensor->data); tensor->data = data_tmp; tensor->device = device; }