cpp代码
#include <iostream>
#include <stdio.h>
#include <stdlib.h> //为rand()及srand()提供函数声明
#include <time.h>
extern "C" int mulWithCuda(float* c,float* a,float* b, int size, int kernelSize);
int main()
{
int size = 10;
float* a = (float*)malloc(size * size * sizeof(float));
float* c = (float*)malloc(size * size * sizeof(float));
float* d = (float*)malloc(size * size * sizeof(float));
srand(time(NULL));
for (int row = 0; row < size; ++row)
{
for (int col = 0; col < size; ++col)
{
a[col + row * size] = (float)rand() / (RAND_MAX / 10);;
c[row * size + col] = 0;
}
}
int kernelSize = 5;
float* b = (float*)malloc(kernelSize * kernelSize * sizeof(float));
for (int i = 0; i < kernelSize * kernelSize; ++i)
{
b[i] = 1;
}
clock_t start = clock();
for (int row = 0; row < size; ++row)
{
for (int col = 0; col < size; ++col)
{
for (int i = 0; i < kernelSize; ++i)
{
for (int j = 0; j < kernelSize; ++j)
{
float v = 0;
//使其定位到左上角坐标系原点,便于后续定位元素
int curRow = row - kernelSize / 2 + i;
int curCol = col - kernelSize / 2 + j;
if (curRow >= 0 && curCol >= 0 &a