Skip to content

Commit 486b704

Browse files
committed
feat: Add cudaStreamSynchronize
To support cudaStreamSynchronize API
1 parent 89e2ea2 commit 486b704

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

qcu-device/hw/misc/virtio-qcuda.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,18 @@ static void qcu_cudaStreamDestroy(VirtioQCArg *arg)
923923
memset(&cudaStream[idx], 0, sizeof(cudaStream_t));
924924
}
925925

926+
static void qcu_cudaStreamSynchronize(VirtioQCArg *arg)
927+
{
928+
cudaError_t err;
929+
uint32_t idx;
930+
idx = arg->pA;
931+
932+
cudaError((err = cudaStreamSynchronize(cudaStream[idx])));
933+
934+
arg->cmd = err;
935+
}
936+
937+
926938
#endif // CONFIG_CUDA
927939

928940
static int qcu_cmd_write(VirtioQCArg *arg)
@@ -1252,6 +1264,10 @@ static void virtio_qcuda_cmd_handle(VirtIODevice *vdev, VirtQueue *vq)
12521264
qcu_cudaStreamDestroy(arg);
12531265
break;
12541266

1267+
case VIRTQC_cudaStreamSynchronize:
1268+
qcu_cudaStreamSynchronize(arg);
1269+
break;
1270+
12551271
// Event Management (runtime API)
12561272
case VIRTQC_cudaEventCreate:
12571273
qcu_cudaEventCreate(arg);

qcu-driver/qcuda_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum
7878
//stream
7979
VIRTQC_cudaStreamCreate,
8080
VIRTQC_cudaStreamDestroy,
81+
VIRTQC_cudaStreamSynchronize,
8182
};
8283

8384
typedef struct VirtioQCArg VirtioQCArg;

qcu-driver/qcuda_driver.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,11 @@ void qcu_cudaStreamDestroy(VirtioQCArg *arg)
10441044
qcu_misc_send_cmd(arg);
10451045
}
10461046

1047+
void qcu_cudaStreamSynchronize(VirtioQCArg *arg)
1048+
{
1049+
qcu_misc_send_cmd(arg);
1050+
}
1051+
10471052

10481053
// @_cmd: device command
10491054
// @_arg: argument of cuda function
@@ -1216,6 +1221,10 @@ static long qcu_misc_ioctl(struct file *filp, unsigned int _cmd, unsigned long _
12161221
qcu_cudaStreamDestroy(arg);
12171222
break;
12181223

1224+
case VIRTQC_cudaStreamSynchronize:
1225+
qcu_cudaStreamSynchronize(arg);
1226+
break;
1227+
12191228
default:
12201229
error("unknow cmd= %d\n", arg->cmd);
12211230
break;

qcu-library/libcudart.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,6 @@ cudaError_t cudaStreamCreate(cudaStream_t *pStream)
821821
cudaError_t cudaStreamDestroy(cudaStream_t stream)
822822
{
823823
VirtioQCArg arg;
824-
825824
memset(&arg, 0, sizeof(VirtioQCArg));
826825

827826
ptr( arg.pA, stream, 0);
@@ -831,6 +830,20 @@ cudaError_t cudaStreamDestroy(cudaStream_t stream)
831830

832831
}
833832

833+
cudaError_t cudaStreamSynchronize(cudaStream_t stream)
834+
{
835+
VirtioQCArg arg;
836+
memset(&arg, 0, sizeof(VirtioQCArg));
837+
838+
uint64_t mystream = (stream==NULL)?(uint64_t)-1:(uint64_t)stream;
839+
840+
ptr( arg.pA, mystream, 0);
841+
842+
send_cmd_to_device( VIRTQC_cudaStreamSynchronize, &arg);
843+
844+
return (cudaError_t)arg.cmd;
845+
}
846+
834847
// Macro to aligned up to the memory size in question
835848
#define MEMORY_ALIGNMENT 4096
836849
#define ALIGN_UP(x,size) ( ((size_t)x+(size-1))&(~(size-1)) )
@@ -869,3 +882,5 @@ cudaError_t cudaFreeHost(void *ptr)
869882
}
870883

871884

885+
886+

0 commit comments

Comments
 (0)