How to access GPU cores to execute parfor loop which has system commands?

8 views (last 30 days)
I am developing an optimization algorithm which has 60 independent iterations inside a parfor loop. I can only deploy 32 workers using parallel computing toolbox as my CPU cores limit to 32. I wish to use gpu for this kind of parallel computing. However my code has system command which runs an executable file from my windows system. The exe is supposed to have 1 input and 1 out put file to read from and write to.
I cannot use gpuarray method as there are no major computations done on a single matrix, but the data is passed using a single control structure. I only intend to use gpu to carry out these multiple instances of independently running system commands inside this parfor loop.
the codes looks something like this,
parfor i = 1:length(Particle) %MATLAB will create Parpool automoatically
disp(['Starting par for loop for particle ',num2str(i)]);
temp1 = load(PSOParmStruct.ModelInfo.RTPStruct_name);
RtpNew = temp1.DefaultRtp;
disp(['Setting up input parameters for particle ',num2str(i)]);
for m = 1:length(PSOParmStruct.Positions)
RtpNew = rsimsetrtpparam(RtpNew,(PSOParmStruct.Positions(m).Name),Particle(i).Positions.(PSOParmStruct.Positions(m).Name));
end
disp(['Loading parameters for particle ',num2str(i)]);
if isfield(PSOParmStruct.ModelInfo,'Parameters')
for m = 1:length(PSOParmStruct.ModelInfo.Parameters)
if isfield(PSOParmStruct.ModelInfo.Parameters(m), 'Name')
if ~isempty(PSOParmStruct.ModelInfo.Parameters(m).Name)
RtpNew = rsimsetrtpparam(RtpNew,(PSOParmStruct.ModelInfo.Parameters(m).Name),...
PSOParmStruct.ModelInfo.Parameters(m).Val);
end
end
end
end
InputFilename = ['Results\',PSOParmStruct.ScriptInfo.RunID,'_',PSOParmStruct.ExecutionInfo.TimeStamp,'\Inputs\Input_Particle_',num2str(Particle(i).ID),'_Iteration_',num2str(Iteration),'.mat'];
ParSave(RtpNew, InputFilename)
OutputFilename = ['Results\',PSOParmStruct.ScriptInfo.RunID,'_',PSOParmStruct.ExecutionInfo.TimeStamp,'\Outputs\Output_Particle_',num2str(Particle(i).ID),'_Iteration_',num2str(Iteration),'.mat'];
Particle(i).SimInput = InputFilename;
Particle(i).SimOutput = OutputFilename;
system([PSOParmStruct.ModelInfo.Executable,' -o ',OutputFilename,' -p ',InputFilename]);
end
the entire above mentioned code is a chunk of a function.
  1 Comment
Walter Roberson
Walter Roberson on 17 Apr 2020
I only intend to use gpu to carry out these multiple instances of independently running system commands inside this parfor loop.
Windows executables cannot themselves run on GPU. They might access a GPU as part of their tasks.
To have any hope, you would need to limit the size of the parpool to the number of GPUs that you have in your system: it is very inefficient to switch a GPU between processes.
GPUs are not just fast CPUs: they have a very very different internal architecture that is sort of like SIMD (Single Instruction, Multiple Data) approach. They do not have an x86 or x64 or ARM based instruction set.

Sign in to comment.

Answers (1)

Matt J
Matt J on 17 Apr 2020
Edited: Matt J on 17 Apr 2020
I cannot use gpuarray method as there are no major computations done on a single matrix, but the data is passed using a single control structure
GPU cores cannot act as individual parfor workers. Their architecture is all wrong for it, as Walter alluded. Accelerating matrix operations on the GPU by way of gpuArrays is largely the only means Matlab offers of benefitting from the GPU that doesn't involve writing your own CUDA code.
If you explain your computation in more detail, it may be possible to recommend how to re-implement it as a matrix operation and in that way capitalize on gpuArrays.

Community Treasure Hunt

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

Start Hunting!