Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongkaifu committed Sep 21, 2024
1 parent 789e01d commit 6c518e6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Seq2SeqSharp/MultiProcessorNetworkWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public MultiProcessorNetworkWrapper(T networkOnDefaultDevice, int[] deviceIds, b
m_isStaticWeights = isStaticWeights;
m_weightsSynced = false;

for (int i = 0; i < deviceIds.Length; i++)
object locker = new object();
Parallel.For(0, deviceIds.Length, i =>
{
if (deviceIds[i] == m_defaultDeviceId)
{
Expand All @@ -48,8 +49,25 @@ public MultiProcessorNetworkWrapper(T networkOnDefaultDevice, int[] deviceIds, b
m_networks[i] = (T)networkOnDefaultDevice.CloneToDeviceAt(deviceIds[i]);
}
m_deviceId2Network.Add(deviceIds[i], m_networks[i]);
}
lock (locker)
{
m_deviceId2Network.Add(deviceIds[i], m_networks[i]);
}
});

//for (int i = 0; i < deviceIds.Length; i++)
//{
// if (deviceIds[i] == m_defaultDeviceId)
// {
// m_networks[i] = networkOnDefaultDevice;
// }
// else
// {
// m_networks[i] = (T)networkOnDefaultDevice.CloneToDeviceAt(deviceIds[i]);
// }

// m_deviceId2Network.Add(deviceIds[i], m_networks[i]);
//}

var raDeviceIds = new RoundArray<int>(deviceIds);
var weights = networkOnDefaultDevice.GetParams();
Expand Down

0 comments on commit 6c518e6

Please sign in to comment.