Change unsigned int to int

This commit is contained in:
2024-03-18 19:40:00 +01:00
parent aac0c3a826
commit e6d3757312
3 changed files with 19 additions and 17 deletions

View File

@@ -39,12 +39,13 @@ __global__ void convolution(
const float* __restrict__ d_input, const float* __restrict__ d_input,
const float* __restrict__ d_kernel, const float* __restrict__ d_kernel,
float* __restrict__ d_output, float* __restrict__ d_output,
const unsigned int inputSize, const int inputSize,
const unsigned int nChannels, const int nChannels,
const unsigned int kernelSize, const int paddingSize,
const unsigned int stride, const int kernelSize,
const unsigned int nFilters, const int stride,
const unsigned int outputSize const int nFilters,
const int outputSize
); );
} // namespace CUDANet::Kernels } // namespace CUDANet::Kernels

View File

@@ -83,12 +83,13 @@ __global__ void CUDANet::Kernels::convolution(
const float* __restrict__ d_input, const float* __restrict__ d_input,
const float* __restrict__ d_kernel, const float* __restrict__ d_kernel,
float* __restrict__ d_output, float* __restrict__ d_output,
const unsigned int inputSize, const int inputSize,
const unsigned int nChannels, const int nChannels,
const unsigned int kernelSize, const int paddingSize,
const unsigned int stride, const int kernelSize,
const unsigned int nFilters, const int stride,
const unsigned int outputSize const int nFilters,
const int outputSize
) { ) {
int tid = blockDim.x * blockIdx.x + threadIdx.x; int tid = blockDim.x * blockIdx.x + threadIdx.x;
@@ -104,9 +105,9 @@ __global__ void CUDANet::Kernels::convolution(
float sum = 0.0f; float sum = 0.0f;
// Iterate over kernel and input matrix // Iterate over kernel and input matrix
for (int k = 0; k < kernelSize; k++) { for (int c = 0; c < nChannels; c++) {
for (int l = 0; l < kernelSize; l++) { for (int k = 0; k < kernelSize; k++) {
for (int c = 0; c < nChannels; c++) { for (int l = 0; l < kernelSize; l++) {
int kernelIndex = f * kernelSize * kernelSize * nChannels + int kernelIndex = f * kernelSize * kernelSize * nChannels +
c * kernelSize * kernelSize + k * kernelSize + c * kernelSize * kernelSize + k * kernelSize +
l; l;

View File

@@ -124,8 +124,8 @@ float* Layers::Conv2d::forward(const float* d_input) {
// Convolve // Convolve
THREADS_PER_BLOCK = outputSize * outputSize * numFilters; THREADS_PER_BLOCK = outputSize * outputSize * numFilters;
Kernels::convolution<<<1, THREADS_PER_BLOCK>>>( Kernels::convolution<<<1, THREADS_PER_BLOCK>>>(
d_padded, d_weights, d_output, inputSize + (2 * paddingSize), d_padded, d_weights, d_output, inputSize + 2 * paddingSize, inputChannels, paddingSize,
inputChannels, kernelSize, stride, numFilters, outputSize kernelSize, stride, numFilters, outputSize
); );
// Add bias // Add bias