-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
810 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/build/ | ||
/cmake-build-debug/ | ||
.DS_Stroe | ||
.vscode |
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
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 +1 @@ | ||
add_executable(shfl_test shfl_test.cu) | ||
add_executable(shfl_test shfl_test.cu) |
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 @@ | ||
add_executable(stream stream.cu) |
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,70 @@ | ||
#include <cuda_runtime.h> | ||
#include <stdio.h> | ||
#include "freshman.h" | ||
|
||
#define N 300000 | ||
__global__ void kernel_1() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
__global__ void kernel_2() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
__global__ void kernel_3() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
__global__ void kernel_4() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
int main() | ||
{ | ||
setenv("CUDA_DEVICE_MAX_CONNECTIONS","32",1); | ||
int dev = 0; | ||
cudaSetDevice(dev); | ||
int n_stream=16; | ||
cudaStream_t *stream=(cudaStream_t*)malloc(n_stream*sizeof(cudaStream_t)); | ||
for(int i=0;i<n_stream;i++) | ||
{ | ||
cudaStreamCreate(&stream[i]); | ||
} | ||
dim3 block(1); | ||
dim3 grid(1); | ||
cudaEvent_t start,stop; | ||
cudaEventCreate(&start); | ||
cudaEventCreate(&stop); | ||
cudaEventRecord(start,0); | ||
for(int i=0;i<n_stream;i++) | ||
{ | ||
kernel_1<<<grid,block,0,stream[i]>>>(); | ||
kernel_2<<<grid,block,0,stream[i]>>>(); | ||
kernel_3<<<grid,block,0,stream[i]>>>(); | ||
kernel_4<<<grid,block,0,stream[i]>>>(); | ||
} | ||
cudaEventRecord(stop,0); | ||
CHECK(cudaEventSynchronize(stop)); | ||
float elapsed_time; | ||
cudaEventElapsedTime(&elapsed_time,start,stop); | ||
printf("elapsed time:%f ms\n",elapsed_time); | ||
|
||
for(int i=0;i<n_stream;i++) | ||
{ | ||
cudaStreamDestroy(stream[i]); | ||
} | ||
cudaEventDestroy(start); | ||
cudaEventDestroy(stop); | ||
free(stream); | ||
CHECK(cudaDeviceReset()); | ||
return 0; | ||
} | ||
|
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,67 @@ | ||
#include <cuda_runtime.h> | ||
#include <stdio.h> | ||
#include "freshman.h" | ||
#include <omp.h> | ||
#define N 300000 | ||
__global__ void kernel_1() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
__global__ void kernel_2() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
__global__ void kernel_3() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
__global__ void kernel_4() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
int main() | ||
{ | ||
int n_stream=4; | ||
cudaStream_t *stream=(cudaStream_t*)malloc(n_stream*sizeof(cudaStream_t)); | ||
for(int i=0;i<n_stream;i++) | ||
{ | ||
cudaStreamCreate(&stream[i]); | ||
} | ||
dim3 block(1); | ||
dim3 grid(1); | ||
cudaEvent_t start,stop; | ||
cudaEventCreate(&start); | ||
cudaEventCreate(&stop); | ||
cudaEventRecord(start,0); | ||
omp_set_num_threads(n_stream); | ||
#pragma omp parallel | ||
{ | ||
int i=omp_get_thread_num(); | ||
kernel_1<<<grid,block,0,stream[i]>>>(); | ||
kernel_2<<<grid,block,0,stream[i]>>>(); | ||
kernel_3<<<grid,block,0,stream[i]>>>(); | ||
kernel_4<<<grid,block,0,stream[i]>>>(); | ||
} | ||
cudaEventRecord(stop,0); | ||
CHECK(cudaEventSynchronize(stop)); | ||
float elapsed_time; | ||
cudaEventElapsedTime(&elapsed_time,start,stop); | ||
printf("elapsed time:%f ms\n",elapsed_time); | ||
|
||
for(int i=0;i<n_stream;i++) | ||
{ | ||
cudaStreamDestroy(stream[i]); | ||
} | ||
cudaEventDestroy(start); | ||
cudaEventDestroy(stop); | ||
free(stream); | ||
return 0; | ||
} |
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 @@ | ||
add_executable(stream_resource stream_resource.cu) |
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,65 @@ | ||
#include <cuda_runtime.h> | ||
#include <stdio.h> | ||
#include "freshman.h" | ||
#define N 100 | ||
__global__ void kernel_1() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
__global__ void kernel_2() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
__global__ void kernel_3() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
__global__ void kernel_4() | ||
{ | ||
double sum=0.0; | ||
for(int i=0;i<N;i++) | ||
sum=sum+tan(0.1)*tan(0.1); | ||
} | ||
int main() | ||
{ | ||
//setenv("CUDA_DEVICE_MAX_CONNECTIONS","32",1); | ||
int n_stream=4; | ||
cudaStream_t *stream=(cudaStream_t*)malloc(n_stream*sizeof(cudaStream_t)); | ||
for(int i=0;i<n_stream;i++) | ||
{ | ||
cudaStreamCreate(&stream[i]); | ||
} | ||
dim3 block(16,32); | ||
dim3 grid(32); | ||
cudaEvent_t start,stop; | ||
cudaEventCreate(&start); | ||
cudaEventCreate(&stop); | ||
cudaEventRecord(start); | ||
for(int i=0;i<n_stream;i++) | ||
{ | ||
kernel_1<<<grid,block,0,stream[i]>>>(); | ||
kernel_2<<<grid,block,0,stream[i]>>>(); | ||
kernel_3<<<grid,block,0,stream[i]>>>(); | ||
kernel_4<<<grid,block,0,stream[i]>>>(); | ||
} | ||
cudaEventRecord(stop); | ||
CHECK(cudaEventSynchronize(stop)); | ||
float elapsed_time; | ||
cudaEventElapsedTime(&elapsed_time,start,stop); | ||
printf("elapsed time:%f ms\n",elapsed_time); | ||
|
||
for(int i=0;i<n_stream;i++) | ||
{ | ||
cudaStreamDestroy(stream[i]); | ||
} | ||
cudaEventDestroy(start); | ||
cudaEventDestroy(stop); | ||
free(stream); | ||
return 0; | ||
} |
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 @@ | ||
add_executable(stream_block stream_block.cu) |
Oops, something went wrong.