Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include "kernel.cuh"
int main()
{
const int arraySize = 5;
const int a[arraySize] = { 1, 2, 3, 4, 5 };
const int b[arraySize] = { 10, 20, 30, 40, 60 };
int c[arraySize] = { 0 };
int vectors_size = 100000;
float* vectors = new float[vectors_size * 4];
float* matrix = new float[16];
float* output = new float[vectors_size * 4];
std::srand(0);
for (int i = 0; i < 16; i++) {
matrix[i] = static_cast<float>(std::rand() % 101)/50.0f-1.0f;
}
for (int i = 0; i < vectors_size*4; i++) {
vectors[i] = static_cast<float>(std::rand() % 101) / 50.0f - 1.0f;
}
// Add vectors in parallel.
cudaError_t cudaStatus = vectorMultiCuda(vectors,vectors_size,matrix,output);
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "addWithCuda failed!");
return 1;
}
std::cout << "vector01: [" << vectors[0] << "," << vectors[1] << "," << vectors[2] << "," << vectors[3] << "]" << std::endl;
std::cout << "matrix: [" << matrix[0] << "," << matrix[1] << "," << matrix[2] << "," << matrix[3] << "]" << std::endl;
std::cout << "vector01: [" << output[0] << "," << output[1] << "," << output[2] << "," << output[3] << "]" << std::endl;
std::cout << "vector02: [" << output[4] << "," << output[5] << "," << output[6] << "," << output[7] << "]" << std::endl;
//printf("{1,2,3,4,5} + {10,20,30,40,50} = {%d,%d,%d,%d,%d}\n", c[0], c[1], c[2], c[3], c[4]);
// cudaDeviceReset must be called before exiting in order for profiling and
// tracing tools such as Nsight and Visual Profiler to show complete traces.
cudaStatus = cudaDeviceReset();
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaDeviceReset failed!");
return 1;
}
return 0;
}