Permalink
Browse files

fixed all the shit (rand)

  • Loading branch information...
1 parent 0846128 commit 3e641a2a08b91d42a2a2dd90c2bfe5c51a6c6833 Ubuntu committed Feb 17, 2017
Showing with 20 additions and 8 deletions.
  1. +20 −8 collision_checking.cu
View
@@ -181,7 +181,7 @@ bool in_collision(double *robot_pose, double *obstacle_space)
-__global__ void freeEdges(double *obstacle_space, bool *isInCollision, double* robot_pose, double* cudaCheckVals)
+__global__ void freeEdges(double *obstacle_space, bool *isInCollision, double* robot_pose, double* cudaCheckVals, double* rand_values)
{
int tid = blockIdx.x * blockDim.x + threadIdx.x;
if (tid >= n_configurations)
@@ -201,7 +201,8 @@ __global__ void freeEdges(double *obstacle_space, bool *isInCollision, double* r
double theta_rand;
for (int i = 1; i <= n_nodes; i++)
{
- theta_rand = 2*M_PI*curand_uniform_double(&state);
+// theta_rand = 2*M_PI*curand_uniform_double(&state);
+ theta_rand = *(rand_values + tid*n_nodes + i);
*(robot_pose + 2*i + 0) = cos(theta_rand) + *(robot_pose + 2*i - 2);
*(robot_pose + 2*i + 1) = sin(theta_rand) + *(robot_pose + 2*i - 1);
}
@@ -366,18 +367,27 @@ int main()
*(robot_pose+i) = -1.0*n_configurations;
}
+ double* rand_numbers;
+ rand_numbers = new double[n_nodes*n_configurations];
+ for (int i = 0; i < n_nodes * n_configurations; i++)
+ {
+ rand_numbers[i] = 2*M_PI*((double) rand()/ (double) RAND_MAX);
+ }
+
bool* cudaIsInCollision;
double* cudaObstacleSpace;
double* cudaRobotPose;
double* cudaCheckVals;
double* checkVals;
-
+ double* cudaRandValues;
+
size_t numbytes_configuration = n_configurations*sizeof(bool);
size_t numbytes_obstacle = 4*n_obstacles*sizeof(double);
size_t numbytes_pose = 2*(n_nodes+1)*sizeof(double);
size_t numbytes_checkVals = (2*n_configurations*(n_nodes+1) + 4 + 3)*sizeof(double);
-
+ size_t numbytes_RandValues = n_nodes * n_configurations *sizeof(double);
+
checkVals = new double[2*n_configurations*(n_nodes+1) + 7];
for (int i = 0; i < (2*n_configurations*(n_nodes+1) + 7); i++)
@@ -389,28 +399,30 @@ int main()
CUDA_CALL( cudaMalloc( &cudaObstacleSpace, 4*n_obstacles*sizeof(double)));
CUDA_CALL( cudaMalloc( &cudaRobotPose, 2*(n_nodes+1)*sizeof(double)));
CUDA_CALL( cudaMalloc( &cudaCheckVals, numbytes_checkVals));
-
+ CUDA_CALL( cudaMalloc( &cudaRandValues, numbytes_RandValues));
CUDA_CALL( cudaMemcpy(cudaIsInCollision, isInCollision, numbytes_configuration, cudaMemcpyHostToDevice));
CUDA_CALL( cudaMemcpy(cudaObstacleSpace, obstacle_space, numbytes_obstacle, cudaMemcpyHostToDevice));
CUDA_CALL( cudaMemcpy(cudaRobotPose, robot_pose, numbytes_pose, cudaMemcpyHostToDevice));
+ CUDA_CALL( cudaMemcpy(cudaRandValues, rand_numbers, numbytes_RandValues, cudaMemcpyHostToDevice));
- freeEdges <<< blocks, threads>>> (cudaObstacleSpace, cudaIsInCollision, cudaRobotPose, cudaCheckVals);
+ freeEdges <<< blocks, threads>>> (cudaObstacleSpace, cudaIsInCollision, cudaRobotPose, cudaCheckVals, cudaRandValues);
CUDA_CHECK();
CUDA_CALL( cudaDeviceSynchronize() );
CUDA_CALL( cudaMemcpy(isInCollision, cudaIsInCollision, numbytes_configuration, cudaMemcpyDeviceToHost));
CUDA_CALL( cudaMemcpy(obstacle_space, cudaObstacleSpace, numbytes_obstacle, cudaMemcpyDeviceToHost));
CUDA_CALL( cudaMemcpy(robot_pose, cudaRobotPose, numbytes_pose, cudaMemcpyDeviceToHost));
CUDA_CALL( cudaMemcpy(checkVals, cudaCheckVals, numbytes_checkVals, cudaMemcpyDeviceToHost));
+ CUDA_CALL( cudaMemcpy(rand_numbers, cudaRandValues, numbytes_RandValues, cudaMemcpyDeviceToHost));
CUDA_CALL( cudaFree(cudaIsInCollision));
CUDA_CALL( cudaFree(cudaObstacleSpace));
CUDA_CALL( cudaFree(cudaRobotPose));
CUDA_CALL( cudaFree(cudaCheckVals));
-
+ CUDA_CALL( cudaFree(cudaRandValues));
int GPUcounts = 0;
for (int i = 0; i < n_configurations; i++)
@@ -440,6 +452,6 @@ int main()
delete[] obstacle_space;
delete[] robot_pose;
delete[] checkVals;
-
+ delete[] rand_numbers;
return 0;
}

0 comments on commit 3e641a2

Please sign in to comment.