# GPU code to numerically integrate parameterized function

3 views (last 30 days)
steve solomon on 25 Jun 2020
Edited: Piotr Balik on 24 Jul 2020
I'm trying to perform an integration in the GPU but haven't managed to figure out how to parse the problem properly. the physics is this (if it's of interest, if not then just skip to code): i have an extended radiance source (blakcbody) that's illuminating a 2D array of pixels. I want to integrate the Planck function over a spectral band that varies from pixel to pixel.
Here's the code, it barfs on the integral.
aoi = 0.9 * ones(nRows,nCols); % dummy values for simplicity
bbTemp = 320;
lambda = [3.000:0.001:5.0]; % filter wavelength grid
transmission = 0.8 * ones(numel(lambda),1)'; % filter transmission
lambdaChi = gpuArray(lambda(end) .* aoi);
lambdaClo = gpuArray(lambda(1) .* aoi);
%%%%%%%%
function spectralRadiance = CalcPlanck(lambda, bbTemp )
h = 6.626070e-34;% J-s, Planck's constant
c = 2.997925e14; % um/s, speed of light in vacuum
k = 1.380649e-23; % J/K, Boltzman's constant
c1p=2e8*c; % ph / sec / cm^2 / um / sr
c2=h*c/k; % um K
end

Piotr Balik on 24 Jul 2020
Edited: Piotr Balik on 24 Jul 2020
I tried to do it, however arrayfun does not allow to insert custom functions:
lambdaClo,lambdaChi);
Error using gpuArray/arrayfun
Creating anonymous functions is not supported.
So that is one problem. I've tested that you can use your own functions, but only if they are on the list:
For example:
function out=myIntegral(in1,in2)
out = expint(in1)-1+in2^2/in1; % integral formula
end
Works alright, so I think you should find Taylor expansion of your integral or any other method (using these allowed) to compute it's value. That is inconvenience, but keeps only fast functions on your gpu.

### Categories

Find more on GPU Computing in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!