Skip to content
Snippets Groups Projects
Commit 6362f483 authored by Eric Wait's avatar Eric Wait
Browse files

Added a kernel class to hold the const kernel

parent 525c408c
No related branches found
No related tags found
No related merge requests found
#include "Kernel.cuh"
#include "CudaUtilities.cuh"
Kernel::Kernel(Vec<size_t> dimensions)
{
dims = dimensions;
kernel.resize(dims.product());
HANDLE_ERROR(cudaMemcpyToSymbol(cudaConstKernel, kernel.data(), sizeof(float)*dims.product()));
}
Kernel::Kernel(Vec<size_t> dimensions, float* values)
{
dims = dimensions;
if (values == NULL)
{
setOnes();
}
else
{
kernel.resize(dims.product());
memcpy(kernel.data(), values, sizeof(float)*dims.product());
}
HANDLE_ERROR(cudaMemcpyToSymbol(cudaConstKernel, kernel.data(), sizeof(float)*dims.product()));
}
void Kernel::setOnes()
{
for (int i = 0; i < dims.product(); ++i)
kernel.push_back(1);
}
#pragma once
#include "Vec.h"
#include <cuda_runtime.h>
#include <vector>
#ifndef CUDA_CONST_KERNEL
#define CUDA_CONST_KERNEL
__constant__ float cudaConstKernel[MAX_KERNEL_DIM*MAX_KERNEL_DIM*MAX_KERNEL_DIM];
#endif
class Kernel
{
public:
Kernel(Vec<size_t> dimensions);
Kernel(Vec<size_t> dimensions, float* values);
~Kernel() { kernel.clear(); }
Vec<size_t> getDimensions() const { return dims; }
const float* getConstPtr() const { return kernel.data(); }
private:
Kernel();
void setOnes();
std::vector<float> kernel;
Vec<size_t> dims;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment