CUDA by example Chapter3 CUDA C简介

阿里云Qwen-Audio-3.0-TTS语音模型部署与实战指南 文本转语音(TTS)技术通过深度学习模型将文字信息转换为自然流畅的语音输出,其核心原理基于序列到序列的神经网络架构。在工程实践中,TTS技术的价值在于为各类应用提供高效的语音合成能力,显著提升人机交互体验。从应用场景来看,TTS广泛应用于智能客服、有声读物、在线教育、内容创作等领域,为语音助手和自动化语音系统提供核心支持。阿里云最新发布的Qwen-Audio-3.0-TTS模型在语音合成质量方面实现重要突破,通过优化的多音字处理和情感调节功能,为开发者提供更加灵活的API接口调用和批量任务处理能力。该模型支 阅读详情

CPU上的Hello World

/*
//代码3.2.1:在CPU上运行C程序
//时间:2019.07.20

#include <iostream>
int main(void)
{
	printf("Hello, world!\n");
	system("pause");
	return 0;
}

GPU上的Hello World

我们将CPU以及系统的内存称为Host,而将GPU及其内存称为Device,在GPU Device上执行的函数通常称为Kernal。

/*
//代码3.2.2:在GPU上运行CUDA C程序,在CPU上运行C程序
//时间:2019.07.20
*/
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>

__global__ void kernal()
{
}

int main(void)
{
	kernal << <1, 1 >> >();
	printf("Hello, world!\n");
	system("pause");
	return 0;
}
*/

与CPU的Hello World相比,GPU的Hello World多了两个值得注意的地方:
(1)一个空的函数kernal(),并且带有修饰符__global__
(2)对这个空函数的调用,并且带有修饰字符<<<1,1>>>

__global__修饰符:

CUDA C为标准C增加了__global__修饰符。这个修饰符将告诉编译器,该函数应该编译为在设备上执行而不是编译为主机执行,__global__修饰符正是Host调用Device的接口
在这个简单是示例中,函数kernal()将被交给编译GPU设备代码的编译器进行编译,而main()函数将被交给CPU主机编译器进行编译。
至于修饰字符<<<1,1>>>我们留在以后再解释,现在只要知道这个修饰字符跟怎样组织GPU的并行性有关即可。

向kernal()中传递参数

/*
//代码3.2.3传递参数
//时间:2019.07.20
*/
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>

__global__ void add(int a,int b,int *c)
{
	*c = a + b;
}

int main(void)
{
	int c;
	int *dev_c;
	//第一个参数是一个指针,指向用于保存新分配内存地址的变量
	//第二个参数是分配内存的大小
	//返回类型为void*,这与C语言中malloc()返回分配内存的指针存在不同
	cudaMalloc((void**)&dev_c, sizeof(int));
	//需要注意的是:
	//可以将cudaMalloc()分配的指针传递给在设备上执行的函数
	//可以在设备代码中使用cudaMalloc()分配的指针进行内存读写操作
	//可以将cudaMalloc()分配的指针传递给在主机上执行的函数
	//不能在主机代码中使用cudaMalloc()分配的指针进行内存读写操作
	add << <1, 1 >> >(2, 4, dev_c);
	//cudaMemcpy,第一个参数是主机指针,第二个参数是设备指针,第三个参数指明内存copy的大小
	//cudaMemcpyDeviceToHost,指明运行时源指针是一个设备指针,而目标指针是一个主机指针
	cudaMemcpy(&c,dev_c,sizeof(int),cudaMemcpyDeviceToHost);

	cudaFree(dev_c);
	printf("2+4=%d\n", c);
	system("pause");
	return 0;

}

在这里插入图片描述
这里新增了多行代码,在这些代码中包含两个概念:
(1)可以像调用C函数那样将参数传递给核函数
(2)当设备执行任何有用的操作时,都需要分配内存

cudaMalloc()函数:

在设备存储空间中为变量分配内存:
cudaMalloc()函数除了分配内存的指针不是作为函数的返回值外,其他的行为与malloc()是相同的,并且返回类型为void *
第一个参数是一个指针,指向用于保存新分配内存地址的变量,第二个参数是分配内存的大小。

注意,程序员一定不能在主机代码中对cudaMalloc()返回的指针进行解引用。
综上,将Device指针的使用限制总结如下:
(1)可以将cudaMalloc()分配的指针传递给在设备上执行的函数
(2)可以在Device代码中使用cudaMalloc()分配的指针进行内存读写操作
(3)可以将cudaMalloc()分配的的指针传递给在主机上执行的函数
(4)不能在主机代码中使用cudaMalloc()分配的指针进行内存读写操作
在这里插入图片描述
主机指针只能访问主机代码中的内存,设备指针只能访问设备代码中的内存。

cudaFree()函数:

类似于标准C中的free()函数,cudaFree用于释放在GPU上分配的空间。

cudaMemcpy()函数:

在主机代码中可以通过调用cudaMemcpy()函数来访问设备上的内存。这个函数调用的行为类似于标准C中的memcpy(),只不过多了一个参数来指定设备内存指针究竟是源指针还是目标指针。

函数参数说明,第一个参数是目标指针,第二个参数是源指针,第三个参数指明内存copy的大小,第四个参数指明内存copy的方向。
比如,目标指针是device,源指针是device,第四个参数设置为cudaMemcpyDeviceToHost,这个参数将指明运行时源指针是一个设备指针,而目标指针是一个主机指针。

查询设备信息

/*
//代码3.3查询设备
//时间:2019.07.20
*/
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>

int main(void)
{
	cudaDeviceProp prop;
	int count;
	cudaGetDeviceCount(&count);
	for (int i = 0; i < count; i++)
	{
		cudaGetDeviceProperties(&prop, i);
		printf("---General Information for device %d ---\n", i);
		printf("Name:%s\n", prop.name);
		printf("Compute capability:%d.%d\n", prop.major, prop.minor);
		printf("Clock rate:%d\n", prop.clockRate);
		printf("Device copy overlap: ");
		if (prop.deviceOverlap)printf("Enabled\n");
		else printf("Disabled\n");
		printf("Kernal execition timeout: ");
		if (prop.kernelExecTimeoutEnabled)printf("Enabled\n");
		else printf("Disabled\n");
		printf("---Memory Information for device %d ---\n", i);
		printf("Total global Mem: %ld\n", prop.totalGlobalMem);
		printf("Total constant Mem: %ld\n", prop.totalConstMem);
		printf("Max mem pitch: %ld\n", prop.memPitch);
		printf("Texture Alignment: %ld\n", prop.textureAlignment);
		printf("---MP Information for device %d ---\n", i);
		printf("Multiprocessor copunt: %d\n", prop.multiProcessorCount);
		printf("Shared mem per mp: %ld\n", prop.sharedMemPerBlock);
		printf("Registers per mp: %d\n", prop.regsPerBlock);
		printf("Threads in warp: %d\n", prop.warpSize);
		printf("Max thread dimensions: (%d,%d,%d)\n",prop.maxThreadsDim[0],prop.maxThreadsDim[1],prop.maxThreadsDim[2]);
		printf("Max grid dimensions: (%d,%d,%d)\n",prop.maxGridSize[0],prop.maxGridSize[1],prop.maxGridSize[2]);
		printf("\n");
	}
	system("pause");

}

在这里插入图片描述

cudaGetDeviceCount()函数:

如果硬件设备中包含有多个CUDA设备,可以通过cudaGetDeviceCount()函数获得CUDA设备的数量。

结构体cudaDeviceProp

用于存储设备的相关属性

/**
 * CUDA device properties
 */
struct __device_builtin__ cudaDeviceProp
{
    char   name[256];                  /**< ASCII string identifying device */
    size_t totalGlobalMem;             /**< Global memory available on device in bytes */
    size_t sharedMemPerBlock;          /**< Shared memory available per block in bytes */
    int    regsPerBlock;               /**< 32-bit registers available per block */
    int    warpSize;                   /**< Warp size in threads */
    size_t memPitch;                   /**< Maximum pitch in bytes allowed by memory copies */
    int    maxThreadsPerBlock;         /**< Maximum number of threads per block */
    int    maxThreadsDim[3];           /**< Maximum size of each dimension of a block */
    int    maxGridSize[3];             /**< Maximum size of each dimension of a grid */
    int    clockRate;                  /**< Clock frequency in kilohertz */
    size_t totalConstMem;              /**< Constant memory available on device in bytes */
    int    major;                      /**< Major compute capability */
    int    minor;                      /**< Minor compute capability */
    size_t textureAlignment;           /**< Alignment requirement for textures */
    size_t texturePitchAlignment;      /**< Pitch alignment requirement for texture references bound to pitched memory */
    int    deviceOverlap;              /**< Device can concurrently copy memory and execute a kernel. Deprecated. Use instead asyncEngineCount. */
    int    multiProcessorCount;        /**< Number of multiprocessors on device */
    int    kernelExecTimeoutEnabled;   /**< Specified whether there is a run time limit on kernels */
    int    integrated;                 /**< Device is integrated as opposed to discrete */
    int    canMapHostMemory;           /**< Device can map host memory with cudaHostAlloc/cudaHostGetDevicePointer */
    int    computeMode;                /**< Compute mode (See ::cudaComputeMode) */
    int    maxTexture1D;               /**< Maximum 1D texture size */
    int    maxTexture1DMipmap;         /**< Maximum 1D mipmapped texture size */
    int    maxTexture1DLinear;         /**< Maximum size for 1D textures bound to linear memory */
    int    maxTexture2D[2];            /**< Maximum 2D texture dimensions */
    int    maxTexture2DMipmap[2];      /**< Maximum 2D mipmapped texture dimensions */
    int    maxTexture2DLinear[3];      /**< Maximum dimensions (width, height, pitch) for 2D textures bound to pitched memory */
    int    maxTexture2DGather[2];      /**< Maximum 2D texture dimensions if texture gather operations have to be performed */
    int    maxTexture3D[3];            /**< Maximum 3D texture dimensions */
    int    maxTexture3DAlt[3];         /**< Maximum alternate 3D texture dimensions */
    int    maxTextureCubemap;          /**< Maximum Cubemap texture dimensions */
    int    maxTexture1DLayered[2];     /**< Maximum 1D layered texture dimensions */
    int    maxTexture2DLayered[3];     /**< Maximum 2D layered texture dimensions */
    int    maxTextureCubemapLayered[2];/**< Maximum Cubemap layered texture dimensions */
    int    maxSurface1D;               /**< Maximum 1D surface size */
    int    maxSurface2D[2];            /**< Maximum 2D surface dimensions */
    int    maxSurface3D[3];            /**< Maximum 3D surface dimensions */
    int    maxSurface1DLayered[2];     /**< Maximum 1D layered surface dimensions */
    int    maxSurface2DLayered[3];     /**< Maximum 2D layered surface dimensions */
    int    maxSurfaceCubemap;          /**< Maximum Cubemap surface dimensions */
    int    maxSurfaceCubemapLayered[2];/**< Maximum Cubemap layered surface dimensions */
    size_t surfaceAlignment;           /**< Alignment requirements for surfaces */
    int    concurrentKernels;          /**< Device can possibly execute multiple kernels concurrently */
    int    ECCEnabled;                 /**< Device has ECC support enabled */
    int    pciBusID;                   /**< PCI bus ID of the device */
    int    pciDeviceID;                /**< PCI device ID of the device */
    int    pciDomainID;                /**< PCI domain ID of the device */
    int    tccDriver;                  /**< 1 if device is a Tesla device using TCC driver, 0 otherwise */
    int    asyncEngineCount;           /**< Number of asynchronous engines */
    int    unifiedAddressing;          /**< Device shares a unified address space with the host */
    int    memoryClockRate;            /**< Peak memory clock frequency in kilohertz */
    int    memoryBusWidth;             /**< Global memory bus width in bits */
    int    l2CacheSize;                /**< Size of L2 cache in bytes */
    int    maxThreadsPerMultiProcessor;/**< Maximum resident threads per multiprocessor */
    int    streamPrioritiesSupported;  /**< Device supports stream priorities */
    int    globalL1CacheSupported;     /**< Device supports caching globals in L1 */
    int    localL1CacheSupported;      /**< Device supports caching locals in L1 */
    size_t sharedMemPerMultiprocessor; /**< Shared memory available per multiprocessor in bytes */
    int    regsPerMultiprocessor;      /**< 32-bit registers available per multiprocessor */
    int    managedMemory;              /**< Device supports allocating managed memory on this system */
    int    isMultiGpuBoard;            /**< Device is on a multi-GPU board */
    int    multiGpuBoardGroupID;       /**< Unique identifier for a group of devices on the same multi-GPU board */
    int    hostNativeAtomicSupported;  /**< Link between the device and the host supports native atomic operations */
    int    singleToDoublePrecisionPerfRatio; /**< Ratio of single precision performance (in floating-point operations per second) to double precision performance */
    int    pageableMemoryAccess;       /**< Device supports coherently accessing pageable memory without calling cudaHostRegister on it */
    int    concurrentManagedAccess;    /**< Device can coherently access managed memory concurrently with the CPU */
    int    computePreemptionSupported; /**< Device supports Compute Preemption */
    int    canUseHostPointerForRegisteredMem; /**< Device can access host registered memory at the same virtual address as the CPU */
    int    cooperativeLaunch;          /**< Device supports launching cooperative kernels via ::cudaLaunchCooperativeKernel */
    int    cooperativeMultiDeviceLaunch; /**< Device can participate in cooperative kernels launched via ::cudaLaunchCooperativeKernelMultiDevice */
    size_t sharedMemPerBlockOptin;     /**< Per device maximum shared memory per block usable by special opt in */
    int    pageableMemoryAccessUsesHostPageTables; /**< Device accesses pageable memory via the host's page tables */
    int    directManagedMemAccessFromHost; /**< Host can directly access managed memory on the device without migration. */
};

cudaGetDeviceProperties()函数:

用于获得指定编号设备的属性信息,第一个参数是cudaDeviceProp类型的指针,第二个参数指定GPU设备编号,如果有N个GPU设备,设备编号从0开始一直到N-1。

cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, 0);//获得第0个GPU设备的属性信息

设备属性的使用:选择一个符合条件约束的设备

/*
//代码3.4设备属性的使用:选择一个符合条件约束的设备
//时间:2019.07.20
*/
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>

int main()
{
	cudaDeviceProp prop;
	int dev;

	//获得当前的GPU设备
	cudaGetDevice(&dev);
	printf("ID of current CUDA device: %d\n", dev);
	//筛选符合要求的设备
	memset(&prop, 0, sizeof(cudaDeviceProp));
	prop.major = 1;
	prop.minor = 3;
	cudaChooseDevice(&dev,&prop);
	printf("ID of CUDA device closet to reversion 1.3: %d\n",dev);

	//设置为筛选出来的GPU设备
	cudaSetDevice(dev);
	system("pause");
}

在这里插入图片描述
假设我们的代码对显卡的版本也有所要求,只有在版本为1.3及以上的计算功能集版本显卡上才能够运行,为了让我们的代码具有更好的鲁棒性,需要筛选出符合要求的GPU来执行代码。
根据cudaGetDeviceCount()和cudaGetDeviceProperties()中返回的结果,我们可以对每个设备进行迭代,并且查找主版本号大于1,或者主版本号为1且次版本号大于等于3的设备。

其实,CUDA运行时提供了一种自动方式来执行这个迭代操作:
首先,找出我们希望设备拥有的属性并将这些属性填充到一个cudaDeviceProp结构中
在填充完cudaDeviceProp之后,将其传递给cudaChooseDevice(),这样CUDA运行时将查找是否存在某个设备满足这些条件。cudaChooseDevice()函数将返回一个设备ID,这个ID就是符合我们筛选要求的GPU,然后我们可以将这个ID传递给cudaSetDevice(),之后所有的设备操作都将在这个设备上执行。

cudaGetDevice()函数:

获得当前运行使用的GPU ID。
输入参数为用于盛放设备ID的地址,cudaGetDevice()函数将用当前设备ID填充这个指针指向的内存。

cudaChooseDevice()函数:

根据cudaDeviceProp设定的筛选条件进行设备筛选。
第一个参数为用于盛放筛选结果的地址,第二个参数为cudaDeviceProp类型筛选条件的内存地址。

cudaSetDevice()函数:

设置使用指定的GPU。
输入参数为指定GPU的ID。

本章小结

1.__global__修饰符
2.cudaMalloc()函数
3.cudaFree()函数
4.cudaMemcpy()函数
5.cudaGetDeviceCount()函数
6.结构体cudaDeviceProp
7.cudaGetDeviceProperties()函数
8.cudaGetDevice()函数
9.cudaChooseDevice()函数
10.cudaSetDevice()函数

CUDA:实现NPP过滤器实例 阅读详情

相关推荐

CUDA by example (中文:GPU高性能编程CUDA实战)代码实例

CUDA by example代码实例

GPU 高性能编程 CUDA : CUDA C 简介

先编写一个 hello world 和 C 没有什么区别我们将 CPU 以及系统的内存称为主机,将 GPU 及其内存称为设备,hello world 示例程序不考虑主机之外的任何计算设备核函数的调用__global__ void kernel ( void ) {}int main(){kernel&lt;&lt;1,1&gt;&gt;();}kernel() 函数,并且带有修饰符 __globa...

xxiaozr的博客 496

cuda by example中文版

cuda 经典的书 很好的入门教程 建议学习gpu的可以看看

CUDA中的统一内存

统一内存尝试通过将数据迁移到正在访问它的设备来优化内存性能(也就是说,如果 CPU 正在访问数据,则将数据移动到主机内存,如果 GPU 将访问它,则将数据移动到设备内存)。数据的物理位置对程序是不可见的,并且可以随时更改,但对数据的虚拟地址的访问将保持有效并且可以从任何处理器保持一致,无论位置如何。如本例所示,在具有 6.x 之前的 GPU 架构的系统上,CPU 线程可能不会在执行内核启动和后续同步调用之间访问任何托管数据,无论 GPU 内核是否实际接触相同的数据(或 任何托管数据)。

专注于人工智能领域的小何尚 3021

ENVI+SARscape实战:从哨兵一号数据到地震形变制图全流程解析

本文详细解析了使用ENVI和SARscape软件从哨兵一号数据生成地震形变图的全流程,包括数据获取、干涉处理、相位解缠等关键步骤。通过实战技巧和参数设置建议,帮助用户高效处理SAR数据,提升地震形变监测的精度和可视化效果。

weixin_30460489的博客 392

ClickHouse的bitmap使用

ClickHouse的bitmap使用 bitmap的基本使用 在CK中bitmap有两种构建方式,在ClickHouse的官网有说明: (1)一个是由聚合函数groupBitmapState构造的, (2)另一个是由Array Object构造的。同时还可以将位图对象转化为数组对象。 bitmap实战 数据和基本数据表准备 创建一张基本表,一个用户表,有多个描述的维度,每个维度由该维度的唯一id。 CREATE TABLE test02(id UInt16, tag1 UInt8, tag2 UInt8,

zg_hover的专栏 5657

cuda c by example - 1

枚举设备属性代码int main( void ) { cudaDeviceProp prop; int count; HANDLE_ERROR( cudaGetDeviceCount( &amp;count ) ); for (int i=0; i&lt; count; i++) { HANDLE_ERROR( cudaGetDeviceProp...

嘿,逮到一只大码农 435

技术文档的语言表达:简洁、准确与易懂的平衡艺术

技术文档的语言表达不仅要简洁、准确,还需要能够打破技术壁垒,使不同背景的读者都能理解。这是一项需要技巧和经验的工作,它要求技术作者既要具备扎实的专业知识,又要具备清晰的表达能力。通过不断打磨语言的简洁性、准确性和易懂性,我们能够创造出一份高质量的技术文档,让知识的传递不再受限于语言的障碍。

人心有反复,好在山水有重逢。 4683

CUDA C 编程指导(一):CUDA介绍

虽然高清实时的3D图像/视频要求日益不能满足市场需求,但是可编程的图像处理单元(GPU)已经演变成具有巨大计算能力和超高存储带宽的高度并行、多线程的多核处理器,如下图, CPU和GPU之间的浮点性能差异的原因是:GPU专门为密集型计算、高度并行计算设计(例如,图像渲染),因此此类设计需要更多的晶体三极管来进行数据处理而不是数据缓存和流程控制,其区别...

weixin_33895604的博客 420

识别产品外观的合格软件_工业视觉工业质检视觉识别机器视觉视觉检测智能制造工业检测缺陷...

随着工业物联网技术的迅猛发展,掀起了以云计算、大数据、以及人工智能 AI 等信息技术正与传统工业深入融合,由此衍生的 “智能制造4.0” 理念,正在为全球工业带来深远变革。中国的制造业巨头也纷纷借此发力,向智能化、数字化制造演进,实施战略转型。如何高效科学的管理和分析制造业务链上的生产价值,推进制造企业生产工艺优化与产品质量提升是每一个制造企业在数字化、智能化转型过程中的必经之路。业务发展带来的挑...

weixin_42502419的博客 756

【Coze 扣子案例】第 23 期・商业篇:一键获取精准商机,自动化招标信息查询与分析

通过地区和项目类型等多维度组合查询全国招标信息网数据,实现招标公告的快速定位。自动解析招标公告内容,提取关键信息,并生成结构化摘要。帮助企业高效获取精准商机,提升市场竞争力,降低人工成本,解决 “信息过载” 与 “精准匹配难” 的双重问题。

weixin_72689845的博客 1935

CUDA by example Chapter4 CUDA C并行编程

CUDA C 并行编程CPU矢量求和运算GPU矢量求和运算尖括号语法<<CPU矢量求和运算 /* //代码4.2.1.1基于CPU的矢量求和运算 //时间:2019.07.20 */ #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> #define N 1...

wolfcsharp的博客 369

华为MetaERP PTP采购到应付全流程解析

摘要:本文系统解析华为MetaERP中的PTP(采购到应付)全流程管理方案,涵盖从采购申请到付款执行的完整业务流程。文章详细分解了PR、PO、GR、IV、AP等关键环节的财务核算规则,并提供了预算校验、库存更新等Python代码示例。同时阐述了IT落地架构设计,包括会计引擎配置、系统集成方案及银企直连支付接口实现。该方案通过三单匹配自动化和智能会计引擎,将处理效率提升10倍(200笔/人天→2000笔/人天),实现98%的自动化率,为集团企业提供了高效的数字化财务管理样板。文中所有技术方案均需根据实际场景调

金牌架构师 1753

《CUDA By Example》【Chapter 04】CUDA C 并行编程

GPU计算的应用前景在很大程度上取决于能否从很多问题中发掘出大规模并行性。 add_loop_cpu.cu #include &amp;amp;amp;amp;quot;../common/book.h&amp;amp;amp;amp;quot; #define N 10 void add( int *a, int *b, int *c ) { int tid = 0; // this is CPU zero, so we start at ze...

wondervictor的博客 299

运维简历优化指南,DeepSeek助您运维简历秒变高分!

例如,当掌握了新的运维技术,如 Serverless 架构的运维管理,就将其添加到简历的专业技能部分,并简要描述在相关项目中的应用情况和成果,如 “在 [项目名称] 中,负责 Serverless 架构的运维工作,成功实现了应用的低成本、高弹性运行,降低了运维成本 30%”。上传简历至 DeepSeek,并输入指令:“请根据以下岗位招聘要求,帮我重新解构我的简历,按照【教育背景→实习经历→项目经历→个人评价→技能证书】的模块,输出一份符合下述岗位的简历,提升我的求职竞争力。

大模型大数据攻城狮的专栏 1477

《CUDA By Example》【Chapter 06】常量内存与事件 ?

6.1 本章目标 高级些的功能,通过GPU上特殊的内存区域来加速应用程序的执行。其中一种内存区域:常量内存(Constant Memory)。介绍一种增强CUDA C应用程序性能的方法,了解如何通过事件来测量应用程序的性能。 如何在CUDA C中使用常量内存 了解常量内存的性能性能 学习使用CUDA事件来测量应用程序的性能 6.2 常量内存 由于GPU有很多ALU, 所以计算能力往...

wondervictor的博客 330

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

CUDA by example Chapter11 多GPU系统上的CUDA C

多GPU系统上的CUDA C零拷贝主机内存通过零拷贝内存实现点积运算零拷贝内存的性能使用多个GPU 零拷贝主机内存 零拷贝主机内存是另一种固定内存,它也不能被CPU从物理内存交换出去或者重新定位。同时,这种内存除了可以用于主机与GPU之间的内存复制外,还可以在CUDA C核函数中直接访问这种类型的主机内存。由于这种内存不需要复制到GPU,因此也称为零拷贝内存。 通过零拷贝内存实现点积运算 1. 测...

wolfcsharp的博客 401

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

《CUDA By Example》【Chapter 03】CUDA C简介

3.2 第一个CUDA程序 simple_kernel.cu #include &amp;amp;quot;../common/book.h&amp;amp;quot; __global__ void kernel( void ) { } int main( void ) { kernel&amp;amp;amp;lt;&amp;amp;amp;lt;&amp;amp;amp;lt;1,1&amp;amp;amp;gt;&amp;amp

wondervictor的博客 362

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

《CUDA By Example》【Chapter 11】多GPU系统上的CUDA C?

11.1 概述 了解如何分配和使用零拷贝内存(zero-copy memory) 了解如何在同一个应用程序中使用多个GPU 了解如何分配和使用可移动的固定内存(Portable pinned Memory) 11.2 零拷贝主机内存 固定内存(页锁定内存)能确保不会交换出物理内存。我们通过调用cudaHostAlloc()来分配这种内存,并且传递参数cudaHostAllocDefa...

wondervictor的博客 618

《CUDA By Example》【Chapter 07】纹理内存 ?

7.1 本章目标 纹理内存和常量内存一样,都是只读内存,用来减少带宽流量,提升性能。 1,了解纹理内存的特性 2,了解如何在CUDA C中使用一维纹理内存 3,了解如何在CUDA C中使用二维纹理内存 7.2 纹理内存简介(Texture Memory) 7.3 热传导模拟...

wondervictor的博客 357

《CUDA By Example》【Chapter 09】原子性?

9.1 概述 了解不同NVIDIA GPU的计算功能集 了解原子操作以及为什么需要使用 了解如何在CUDA C核函数中执行带有原子操作的运算 9.2 计算功能集 不同架构的CPU有不同的功能和指令集(如MMX,SSE,SSE2),对于CUDA支持的GPU也一样。NVIDIA将GPU支持的各种功能统称为计算功能集(Compute Capability)。 9.2.1 NVIDIA...

wondervictor的博客 366

《CUDA By Example》【Chapter 08】图形互操作性?

8.1 本章目的 本书重点为通用计算。GPU的成功要归功于实时计算复杂的渲染任务。能否同一个应用程序中GPU既执行渲染计算,又执行通用计算? CUDA C支持通用计算与渲染模式之间的互操作,而且非常容易实现。CUDA C可以无缝的与OpenGL和DirectX这两种实时渲染API进行交互。 目标: 什么是图形互操作性 如何设置某个CUDA设备的图形互操作性 如何在CUDA ...

wondervictor的博客 370

10分钟搞懂CUDA线程模型:Grid、Block与Thread核心概念(Hands-On GPU加速计算机视觉)

想用GPU加速计算机视觉任务,第一关就是理解**CUDA线程模型**。Hands-On GPU Accelerated Computer Vision with OpenCV and CUDA(Packt 出版的实战教程)在前四章用大量可运行示例,把 Grid、Block、Thread 这三个层级讲得清清楚楚。本文将用 10 分钟带你吃透这套核心概念,并配合项目源码,看看 CUDA 线程模型如何驱

gitblog_00341的博客 188

CANN Ascend C资料设计规范

Ascend C documentation is the sole official entry point for developers using Ascend NPUs for operator development. Documentation quality directly impacts developer efficiency across the entire "unders

gitblog_00820的博客 391

happy-llm 大模型训练排障实战:从环境自检到训练推理的 5 类故障快速定位

先把最近训练现场最常见的几段日志贴出来: ```text RuntimeError: CUDA out of memory. Tried to allocate 2.50 GiB ValueError: Token indices sequence length is longer than the specified maximum sequence length # SwanLab 截图:l

gitblog_00157的博客 341
上一篇: PCL使用积分图像估计点云的表面法线
下一篇: CUDA by example Chapter4 CUDA C并行编程
Leo-Ma
博客等级 码龄11年 1702粉丝 124原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值