diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-11-12 12:02:02 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-11-12 12:02:02 -0500 |
| commit | 9b3243f726a65d9ef802e4b94efc4bb334cb9174 (patch) | |
| tree | b887ec8b97505df3c315f5105a650938b826a132 | |
| parent | 0009a25716a502de8b931f46e0c7d67b6a1bd437 (diff) | |
| download | balls-9b3243f726a65d9ef802e4b94efc4bb334cb9174.zip | |
create velocity buffer
| -rw-r--r-- | balls.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -304,23 +304,23 @@ setPositions(void) { void setVelocities(void) { - float *hostVelocities; + float *velocitiesHostBuf; int i, err; /* Generate initial ball velocities. */ - if ((hostVelocities = malloc(nBalls*2*sizeof(float))) == NULL) + if ((velocitiesHostBuf = malloc(nBalls*2*sizeof(float))) == NULL) sysfatal("Failed to allocate velocity array.\n"); for (i = 0; i < nBalls; i++) { - hostVelocities[2*i] = randFloat(-VMAX_INIT, VMAX_INIT); - hostVelocities[2*i+1] = randFloat(-VMAX_INIT, VMAX_INIT); + velocitiesHostBuf[2*i] = randFloat(-VMAX_INIT, VMAX_INIT); + velocitiesHostBuf[2*i+1] = randFloat(-VMAX_INIT, VMAX_INIT); } /* Create device-side buffer. */ - velocities = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, nBalls*2*sizeof(float), hostVelocities, &err); + velocitiesCpuBuf = clCreateBuffer(cpuContext, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, nBalls*2*sizeof(float), velocitiesHostBuf, &err); if (err < 0) sysfatal("Failed to allocate velocity buffer.\n"); - free(hostVelocities); + free(velocitiesHostBuf); } void |