Skip to content

[RNN] Dynamic algo optimization #3470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 7, 2025
12 changes: 10 additions & 2 deletions driver/rnn_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ int RNNDriver<Tgpu, Tref>::SetRNNDescriptorFromCmdLineArgs()
{
algo = miopenRNNfundamental;
}
else if((inflags.GetValueInt("rnnalgo")) == 2)
{
algo = miopenRNNroundedDynamic;
}
else
{
printf("Incorrect RNN algorithm\n");
Expand Down Expand Up @@ -616,7 +620,9 @@ int RNNDriver<Tgpu, Tref>::AllocateBuffersAndCopy()
workspace = std::vector<Tgpu>(workSpace_sz, static_cast<Tgpu>(0));
reservespace = std::vector<Tgpu>(reserveSpace_sz, static_cast<Tgpu>(0));
outhost = std::vector<Tref>(out_sz, static_cast<Tref>(0));
workspace_host = std::vector<Tref>(workSpace_sz, static_cast<Tref>(0));
workspace_host = (inflags.GetValueInt("verify") == 1)
? std::vector<Tref>(workSpace_sz, static_cast<Tref>(0))
: std::vector<Tref>{};

int nseq = inflags.GetValueInt("seq_len");
std::vector<int> in_n = GetInputTensorLengthsFromCmdLine();
Expand All @@ -641,7 +647,9 @@ int RNNDriver<Tgpu, Tref>::AllocateBuffersAndCopy()
reserveSpaceHost_sz += (layer - 1) * inputBatchLenSum * hid_h * (bidir + 1);
reserveSpaceHost_sz = (reserveSpaceHost_sz + sizeof(Tref) - 1) / sizeof(Tref);
}
reservespace_host = std::vector<Tref>(reserveSpaceHost_sz, static_cast<Tref>(0));
reservespace_host = (inflags.GetValueInt("verify") == 1)
? std::vector<Tref>(reserveSpaceHost_sz, static_cast<Tref>(0))
: std::vector<Tref>{};

if(inflags.GetValueInt("forw") != 1)
{
Expand Down
19 changes: 13 additions & 6 deletions driver/rnn_seq_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ int RNNSeqDriver<Tgpu, Tref>::SetRNNDescriptorFromCmdLineArgs()
{
algo = miopenRNNfundamental;
}
else if((inflags.GetValueInt("rnnalgo")) == 2)
{
algo = miopenRNNroundedDynamic;
}
else
{
printf("Incorrect RNN algorithm\n");
Expand Down Expand Up @@ -906,7 +910,9 @@ int RNNSeqDriver<Tgpu, Tref>::AllocateBuffersAndCopy()
workspace = std::vector<Tgpu>(workSpace_sz, static_cast<Tgpu>(0));
reservespace = std::vector<Tgpu>(reserveSpace_sz, static_cast<Tgpu>(0));
outhost = std::vector<Tref>(out_host_sz, static_cast<Tref>(0));
workspace_host = std::vector<Tref>(workSpace_sz, static_cast<Tref>(0));
workspace_host = (inflags.GetValueInt("verify") == 1)
? std::vector<Tref>(workSpace_sz, static_cast<Tref>(0))
: std::vector<Tref>{};

/// dropout legacy format
const std::size_t inputBatchLenSum = vectors_cnt_host;
Expand All @@ -927,7 +933,9 @@ int RNNSeqDriver<Tgpu, Tref>::AllocateBuffersAndCopy()
reserveSpaceHost_sz += (layer - 1) * inputBatchLenSum * hid_h * (bidir + 1);
reserveSpaceHost_sz = (reserveSpaceHost_sz + sizeof(Tref) - 1) / sizeof(Tref);
}
reservespace_host = std::vector<Tref>(reserveSpaceHost_sz, static_cast<Tref>(0));
reservespace_host = (inflags.GetValueInt("verify") == 1)
? std::vector<Tref>(reserveSpaceHost_sz, static_cast<Tref>(0))
: std::vector<Tref>{};
// end dropout

if(inflags.GetValueInt("forw") != 1)
Expand Down Expand Up @@ -1078,13 +1086,12 @@ int RNNSeqDriver<Tgpu, Tref>::RunForwardGPU()
RNNCombTimeLoger t(GetStream(), inflags.GetValueInt("iter"), inflags.GetValueInt("wall"));

from_gpu_out = std::vector<Tgpu>(out_dev->GetSize() / sizeof(Tgpu), static_cast<Tgpu>(0));
out_dev->ToGPU(q, from_gpu_out.data());
workspace_dev->ToGPU(q, workspace.data());
reservespace_dev->ToGPU(q, reservespace.data());

for(int i = 0; i < inflags.GetValueInt("iter"); i++)
{
out_dev->ToGPU(q, from_gpu_out.data());
workspace_dev->ToGPU(q, workspace.data());
reservespace_dev->ToGPU(q, reservespace.data());

t.Start();
miopenRNNForward(GetHandle(),
rnnDesc,
Expand Down
Loading
Loading