-
Notifications
You must be signed in to change notification settings - Fork 363
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 #727 from Bertk/cuda
support cudaKernel grammar
- Loading branch information
Showing
5 changed files
with
62 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// define project specific values to reduce parsing errors | ||
#define __global__ | ||
#define __host__ | ||
#define __device__ | ||
#define __noinline__ | ||
#define __forceinline__ | ||
#define __constant__ | ||
#define __shared__ | ||
#dfeine __managed__ | ||
#define __restrict__ | ||
#define __align__(a) |
41 changes: 41 additions & 0 deletions
41
cxx-squid/src/test/resources/parser/cuda/kernel_function.cpp
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,41 @@ | ||
#include "cuda-defines.h" | ||
|
||
texture<float, 2, cudaReadModeElementType> tex; | ||
|
||
void foo() | ||
{ | ||
cudaArray* cu_array; | ||
|
||
// Allocate array | ||
cudaChannelFormatDesc description = cudaCreateChannelDesc<float>(); | ||
cudaMallocArray(&cu_array, &description, width, height); | ||
|
||
// Copy image data to array | ||
cudaMemcpyToArray(cu_array, image, width*height*sizeof(float), cudaMemcpyHostToDevice); | ||
|
||
// Set texture parameters (default) | ||
tex.addressMode[0] = cudaAddressModeClamp; | ||
tex.addressMode[1] = cudaAddressModeClamp; | ||
tex.filterMode = cudaFilterModePoint; | ||
tex.normalized = false; // do not normalize coordinates | ||
|
||
// Bind the array to the texture | ||
cudaBindTextureToArray(tex, cu_array); | ||
|
||
// Run kernel | ||
dim3 blockDim(16, 16, 1); | ||
dim3 gridDim((width + blockDim.x - 1)/ blockDim.x, (height + blockDim.y - 1) / blockDim.y, 1); | ||
kernel<<< gridDim, blockDim, 0 >>>(d_data, height, width); | ||
// Unbind the array from the texture | ||
cudaUnbindTexture(tex); | ||
} //end foo() | ||
|
||
__global__ void kernel(float* odata, int height, int width) | ||
{ | ||
unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; | ||
unsigned int y = blockIdx.y*blockDim.y + threadIdx.y; | ||
if (x < width && y < height) { | ||
float c = tex2D(tex, x, y); | ||
odata[y*width+x] = c; | ||
} | ||
} |