Apply consistent code formatting across the repo. Add clang-format and pre-commit hooks.

This commit is contained in:
Rob Armstrong
2025-03-27 10:30:07 -07:00
parent 2cd58fbc9a
commit ceab6e8bcc
782 changed files with 107230 additions and 106548 deletions

View File

@@ -30,24 +30,23 @@
*/
// System includes
#include <stdio.h>
#include <assert.h>
#include <stdio.h>
// CUDA runtime
#include <cuda_runtime.h>
// helper functions and utilities to work with CUDA
#include <helper_functions.h>
#include <helper_cuda.h>
#include <helper_functions.h>
__global__ void sequence_gpu(int *d_ptr, int length)
{
int elemID = blockIdx.x * blockDim.x + threadIdx.x;
if (elemID < length)
{
if (elemID < length) {
unsigned int laneid;
//This command gets the lane ID within the current warp
// This command gets the lane ID within the current warp
asm("mov.u32 %0, %%laneid;" : "=r"(laneid));
d_ptr[elemID] = laneid;
}
@@ -56,8 +55,7 @@ __global__ void sequence_gpu(int *d_ptr, int length)
void sequence_cpu(int *h_ptr, int length)
{
for (int elemID=0; elemID<length; elemID++)
{
for (int elemID = 0; elemID < length; elemID++) {
h_ptr[elemID] = elemID % 32;
}
}
@@ -68,10 +66,9 @@ int main(int argc, char **argv)
const int N = 1000;
int dev = findCudaDevice(argc, (const char **) argv);
int dev = findCudaDevice(argc, (const char **)argv);
if (dev == -1)
{
if (dev == -1) {
return EXIT_FAILURE;
}
@@ -81,7 +78,7 @@ int main(int argc, char **argv)
int *h_ptr;
checkCudaErrors(cudaMallocHost(&h_ptr, N * sizeof(int)));
dim3 cudaBlockSize(256,1,1);
dim3 cudaBlockSize(256, 1, 1);
dim3 cudaGridSize((N + cudaBlockSize.x - 1) / cudaBlockSize.x, 1, 1);
sequence_gpu<<<cudaGridSize, cudaBlockSize>>>(d_ptr, N);
checkCudaErrors(cudaGetLastError());
@@ -90,15 +87,13 @@ int main(int argc, char **argv)
sequence_cpu(h_ptr, N);
int *h_d_ptr;
checkCudaErrors(cudaMallocHost(&h_d_ptr, N *sizeof(int)));
checkCudaErrors(cudaMemcpy(h_d_ptr, d_ptr, N *sizeof(int), cudaMemcpyDeviceToHost));
checkCudaErrors(cudaMallocHost(&h_d_ptr, N * sizeof(int)));
checkCudaErrors(cudaMemcpy(h_d_ptr, d_ptr, N * sizeof(int), cudaMemcpyDeviceToHost));
bool bValid = true;
for (int i=0; i<N && bValid; i++)
{
if (h_ptr[i] != h_d_ptr[i])
{
for (int i = 0; i < N && bValid; i++) {
if (h_ptr[i] != h_d_ptr[i]) {
bValid = false;
}
}
@@ -109,5 +104,5 @@ int main(int argc, char **argv)
checkCudaErrors(cudaFreeHost(h_ptr));
checkCudaErrors(cudaFreeHost(h_d_ptr));
return bValid ? EXIT_SUCCESS: EXIT_FAILURE;
return bValid ? EXIT_SUCCESS : EXIT_FAILURE;
}