matlab 配置gpu,Type for MATLAB gpuArray

本文介绍mxGPUArray,一种允许MEX函数访问MATLAB gpuArray元素的不透明C语言类型。通过mxGPU API,可以在MATLAB中对gpuArray进行操作,并将结果返回到MATLAB。文章还详细介绍了如何在MEX函数中使用mxGPUArray对象,包括初始化、获取设备指针、调用CUDA函数等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

mxGPUArray is an opaque C language type that allows a MEX function

access to the elements in a MATLAB gpuArray. Using the mxGPU API,

you can perform calculations on a MATLAB gpuArray, and return gpuArray

results to MATLAB.

All MEX functions receive inputs and pass outputs as mxArrays.

A gpuArray in MATLAB is a special kind of mxArray that represents

an array stored on the GPU. In your MEX function, you use mxGPUArray

objects to access an array stored on the GPU: these objects correspond

to MATLAB gpuArrays.

The mxGPU API contains functions that manipulate mxGPUArray objects.

These functions allow you to extract mxGPUArrays from input mxArrays,

to wrap output mxGPUArrays as mxArrays for return to MATLAB, to determine

the characteristics of the arrays, and to get pointers to the underlying

elements. You can perform calculations by passing the pointers to

CUDA functions that you write or that are available in external libraries.

The basic structure of a GPU MEX function is:

Call mxInitGPU to

initialize MathWorks GPU library.

Determine which mxArray inputs

contain GPU data.

Create mxGPUArray objects from

the input mxArray arguments, and get pointers to

the input elements on the device.

Create mxGPUArray objects to hold

the outputs, and get the pointers to the output elements on the device.

Call a CUDA function, passing it the device pointers.

Wrap the output mxGPUArray as an mxArray for

return to MATLAB.

Destroy the mxGPUArray objects

you created.

The header file that contains this type is mxGPUArray.h.

You include it with the line:

#include "gpu/mxGPUArray.h"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值