kernel.h
#pragma once
cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size);
kernel.cu
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size);
__global__ void addKernel(int *c, const int *a, const int *b)
{
int i = threadIdx.x;
c[i] = a[i] + b[i];
}
// Helper function for using CUDA to add vectors in parallel.
cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size)
{
int *dev_a = 0;

本文档介绍了如何将CUDA源文件,如kernel.cu和test.cu,编译成静态库。通过这个过程,开发者可以将CUDA内核函数封装在静态库中,方便在不同项目中复用。首先,需要包含kernel.h头文件,然后分别编译cu文件和测试文件,最后链接生成静态库。
最低0.47元/天 解锁文章
273

被折叠的 条评论
为什么被折叠?



