-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jcamachado/feat/cudafy-particles
Feat/cudafy particles
- Loading branch information
Showing
23 changed files
with
242 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <math.h> | ||
#include <stdio.h> | ||
|
||
#define THREADS 8 // 1000 threads per block | ||
#define ARRAYSIZE 8 | ||
|
||
// Professor, nao lembro do exemplo que o senhor fez em aula, e nao | ||
// consegui achar o seu slide, entao inventei um exemplo para testar | ||
|
||
|
||
// Um teste de troca de elementos pelo seu corresponde na outra metade do vetor | ||
// apos se dobrar) | ||
// exemplo: um array de tamanho N | ||
// a[0] *= 2 | ||
// se index < n/2 | ||
// a[index] = a[(index + n/2)+1] //em caso de impar, o elemento do meio nao sera trocado | ||
// ex: input:[0, 1, 5, 3, 7] | ||
// output:[6, 14, 10, 0, 2] | ||
__global__ void swapElement(int* data){ | ||
int index = threadIdx.x + blockIdx.x * blockDim.x; | ||
__shared__ int shared[ARRAYSIZE]; | ||
int aux; | ||
shared[threadIdx.x] = data[threadIdx.x]; | ||
shared[index] *= 2; | ||
__syncthreads(); //Se remover, o comportamento sera indeterminado | ||
if (index < ARRAYSIZE/2) | ||
aux = shared[index]; | ||
shared[index] = shared[(index + (ARRAYSIZE+1)/2)]; | ||
shared[(index + (ARRAYSIZE+1)/2)] = aux; | ||
__syncthreads(); | ||
data[threadIdx.x] = shared[threadIdx.x]; | ||
} | ||
|
||
int main(){ | ||
int *a, *d_a; | ||
|
||
a = (int*) malloc(sizeof(int) * ARRAYSIZE); | ||
for(int i = 0; i < ARRAYSIZE; i++){ | ||
a[i] = i; | ||
} | ||
|
||
printf("\nTeste Entrada\n"); | ||
|
||
printf("%d ", a[0]); | ||
for(int i = 0; i < ARRAYSIZE; i++){ | ||
printf("%d ", a[i]); | ||
} | ||
cudaMalloc((void**) &d_a, sizeof(int)*ARRAYSIZE); | ||
cudaMemcpy(d_a, a, sizeof(int) * ARRAYSIZE, cudaMemcpyHostToDevice); | ||
|
||
swapElement<<<1,THREADS>>>(d_a); | ||
|
||
cudaMemcpy(a, d_a, sizeof(int) * ARRAYSIZE, cudaMemcpyDeviceToHost); | ||
|
||
printf("\nTeste saida: \n"); | ||
|
||
// for(int i = 0; i < ARRAYSIZE; i++){ | ||
// //first element is | ||
// if(i % 10 == 0){ | ||
// printf("\n"); | ||
// } | ||
// printf("%d ", a[i]); | ||
|
||
// } | ||
printf("%d ", a[0]); | ||
for(int i = 0; i < ARRAYSIZE; i++){ | ||
printf("%d ", a[i]); | ||
|
||
} | ||
|
||
free(a); | ||
cudaFree(d_a); | ||
return 0; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,119 @@ | ||
#include <GL/glut.h> | ||
#include "glm/glm.hpp" | ||
#include <vector> | ||
// #include <GL/glut.h> | ||
// #include "glm/glm.hpp" | ||
// #include <vector> | ||
|
||
|
||
struct Mesh | ||
{ | ||
GLuint PositionHandle; | ||
GLuint NormalHandle; | ||
GLuint IndexHandle; | ||
// struct Mesh | ||
// { | ||
// GLuint PositionHandle; | ||
// GLuint NormalHandle; | ||
// GLuint IndexHandle; | ||
|
||
unsigned int IndexBufferLength; | ||
// unsigned int IndexBufferLength; | ||
|
||
// Mesh(); | ||
// Mesh(std::vector<float> const & Positions, std::vector<float> const & Normals, std::vector<unsigned short> const & Indices); | ||
// void Draw(); | ||
// }; | ||
|
||
// Mesh * GeometryCreator::CreateCube(glm::vec3 const & Size) | ||
// { | ||
// std::vector<float> Positions, Normals; | ||
// std::vector<unsigned short> Indices; | ||
|
||
// static float const CubePositions[] = | ||
// { | ||
// -0.5, -0.5, -0.5, // back face verts [0-3] | ||
// -0.5, 0.5, -0.5, | ||
// 0.5, 0.5, -0.5, | ||
// 0.5, -0.5, -0.5, | ||
|
||
// -0.5, -0.5, 0.5, // front face verts [4-7] | ||
// -0.5, 0.5, 0.5, | ||
// 0.5, 0.5, 0.5, | ||
// 0.5, -0.5, 0.5, | ||
|
||
// -0.5, -0.5, 0.5, // left face verts [8-11] | ||
// -0.5, -0.5, -0.5, | ||
// -0.5, 0.5, -0.5, | ||
// -0.5, 0.5, 0.5, | ||
|
||
// 0.5, -0.5, 0.5, // right face verts [12-15] | ||
// 0.5, -0.5, -0.5, | ||
// 0.5, 0.5, -0.5, | ||
// 0.5, 0.5, 0.5, | ||
|
||
// -0.5, 0.5, 0.5, // top face verts [16-19] | ||
// -0.5, 0.5, -0.5, | ||
// 0.5, 0.5, -0.5, | ||
// 0.5, 0.5, 0.5, | ||
|
||
// -0.5, -0.5, 0.5, // bottom face verts [20-23] | ||
// -0.5, -0.5, -0.5, | ||
// 0.5, -0.5, -0.5, | ||
// 0.5, -0.5, 0.5 | ||
// }; | ||
// Positions = std::vector<float>(CubePositions, CubePositions + 24 * 3); | ||
// int i = 0; | ||
// for (std::vector<float>::iterator it = Positions.begin(); it != Positions.end(); ++ it, ++ i) | ||
// * it *= Size[i %= 3]; | ||
|
||
// static float const CubeNormals[] = | ||
// { | ||
// 0, 0, -1, // back face verts [0-3] | ||
// 0, 0, -1, | ||
// 0, 0, -1, | ||
// 0, 0, -1, | ||
|
||
// 0, 0, 1, // front face verts [4-7] | ||
// 0, 0, 1, | ||
// 0, 0, 1, | ||
// 0, 0, 1, | ||
|
||
// -1, 0, 0, // left face verts [8-11] | ||
// -1, 0, 0, | ||
// -1, 0, 0, | ||
// -1, 0, 0, | ||
|
||
// 1, 0, 0, // right face verts [12-15] | ||
// 1, 0, 0, | ||
// 1, 0, 0, | ||
// 1, 0, 0, | ||
|
||
// 0, 1, 0, // top face verts [16-19] | ||
// 0, 1, 0, | ||
// 0, 1, 0, | ||
// 0, 1, 0, | ||
|
||
// 0, -1, 0, // bottom face verts [20-23] | ||
// 0, -1, 0, | ||
// 0, -1, 0, | ||
// 0, -1, 0 | ||
// }; | ||
// Normals = std::vector<float>(CubeNormals, CubeNormals + 24 * 3); | ||
|
||
// static unsigned short const CubeIndices[] = | ||
// { | ||
// 0, 1, 2, // back face verts [0-3] | ||
// 2, 3, 0, | ||
|
||
// 4, 7, 6, // front face verts [4-7] | ||
// 6, 5, 4, | ||
|
||
// 8, 11, 10, // left face verts [8-11] | ||
// 10, 9, 8, | ||
|
||
// 12, 13, 14, // right face verts [12-15] | ||
// 14, 15, 12, | ||
|
||
// 16, 19, 18, // top face verts [16-19] | ||
// 18, 17, 16, | ||
|
||
// 20, 21, 22, // bottom face verts [20-23] | ||
// 22, 23, 20 | ||
// }; | ||
// Indices = std::vector<unsigned short>(CubeIndices, CubeIndices + 12 * 3); | ||
|
||
// return new Mesh(Positions, Normals, Indices); | ||
// } | ||
|
||
Mesh(); | ||
Mesh(std::vector<float> const & Positions, std::vector<float> const & Normals, std::vector<unsigned short> const & Indices); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+16.6 MB
...gFaPjyY7dcUT5F6nd7XWkApYB7aSjMrNgmy0VI72vdV91q-LALHx8yQfs6ia6mZsRKNkIYTNLRbyQ_kgv7YsgGg1Q
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.