Clear Filters
Clear Filters

GPU code to numerically integrate parameterized function

7 views (last 30 days)
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
radiance = zeros(nRows, nCols);
radianceGpu = gpuArray(radiance);
spectralRadiance = @CalcPlanck;
lambdaChi = gpuArray(lambda(end) .* aoi);
lambdaClo = gpuArray(lambda(1) .* aoi);
radianceGpu = integral(@(x)spectralRadiance(x,bbTemp), lambdaClo, lambdaChi);
%%%%%%%%
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
spectralRadiance = c1p./(lambda.^4)./(exp(c2./(lambda.*bbTemp))-1);
end

Answers (1)

Piotr Balik
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:
radianceGpu = arrayfun( @(lower,upper) integral(@(x)spectralRadiance(x,bbTemp),lower,upper),...
lambdaClo,lambdaChi);
Error using gpuArray/arrayfun
Creating anonymous functions is not supported.
For more information see Tips and Restrictions.
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:
radianceGpu = arrayfun( @myIntegral,lambdaClo,lambdaChi);
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.

Products

Community Treasure Hunt

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

Start Hunting!