Skip to content

Commit

Permalink
Merge branch 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yongqiang Wang committed Nov 30, 2015
2 parents 327d978 + 56a565d commit 7e05bb7
Show file tree
Hide file tree
Showing 231 changed files with 6,618 additions and 6,700 deletions.
30 changes: 15 additions & 15 deletions BrainScript/BrainScriptEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace Microsoft { namespace MSR { namespace BS {
{
size_t pos = how.find(L'%');
if (pos != wstring::npos)
RuntimeError("FormatConfigValue: format string must not contain %");
RuntimeError("FormatConfigValue: format string must not contain %%");
if (arg.Is<String>())
{
return wstrprintf((L"%" + how + L"s").c_str(), arg.AsRef<String>().c_str());
Expand Down Expand Up @@ -139,7 +139,7 @@ namespace Microsoft { namespace MSR { namespace BS {
typedef shared_ptr<ComputationNode> ComputationNodePtr;

// inputs and output
vector<ComputationNodePtr> m_children; // these are the inputs
vector<ComputationNodePtr> m_inputs; // these are the inputs
MatrixPtr m_functionValue; // this is the result

// other
Expand Down Expand Up @@ -183,42 +183,42 @@ namespace Microsoft { namespace MSR { namespace BS {

virtual void AttachInputs(ComputationNodePtr arg)
{
m_children.resize(1);
m_children[0] = arg;
m_inputs.resize(1);
m_inputs[0] = arg;
}
virtual void AttachInputs(ComputationNodePtr leftNode, ComputationNodePtr rightNode)
{
m_children.resize(2);
m_children[0] = leftNode;
m_children[1] = rightNode;
m_inputs.resize(2);
m_inputs[0] = leftNode;
m_inputs[1] = rightNode;
}
virtual void AttachInputs(ComputationNodePtr arg1, ComputationNodePtr arg2, ComputationNodePtr arg3)
{
m_children.resize(3);
m_children[0] = arg1;
m_children[1] = arg2;
m_children[2] = arg3;
m_inputs.resize(3);
m_inputs[0] = arg1;
m_inputs[1] = arg2;
m_inputs[2] = arg3;
}
void AttachInputs(vector<ComputationNodePtr> && inputs, size_t num = 0/*0 means all OK*/)
{
if (num != 0 && inputs.size() != num)
LogicError("AttachInputs: called with incorrect number of arguments");
m_children = inputs;
m_inputs = inputs;
}
const std::vector<ComputationNodePtr> & GetChildren() const { return m_children; }
const std::vector<ComputationNodePtr> & GetChildren() const { return m_inputs; }

/*HasToString::*/ wstring ToString() const
{
// we format it like "[TYPE] ( args )"
wstring result = TidyName(NodeName()) + L" : " + wstring(OperationName());
if (!m_tag.empty())
result += L" {tag: " + m_tag + L"}";
if (m_children.empty()) result.append(L"()");
if (m_inputs.empty()) result.append(L"()");
else
{
wstring args;
bool first = true;
for (auto & child : m_children)
for (auto & child : m_inputs)
{
if (first)
first = false;
Expand Down
49 changes: 48 additions & 1 deletion CNTK.sln
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LSTM", "LSTM", "{19EE975B-232D-49F0-94C7-6F1C6424FB53}"
ProjectSection(SolutionItems) = preProject
Tests\Speech\LSTM\cntk.config = Tests\Speech\LSTM\cntk.config
..\..\..\..\..\work\cntk-public\Tests\Speech\LSTM\lstm.bs = ..\..\..\..\..\work\cntk-public\Tests\Speech\LSTM\lstm.bs
Tests\Speech\LSTM\lstm.bs = Tests\Speech\LSTM\lstm.bs
Tests\Speech\DNN\DiscriminativePreTraining\macros.txt = Tests\Speech\DNN\DiscriminativePreTraining\macros.txt
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ParseConfig", "MachineLearning\ParseConfig\ParseConfig.vcxproj", "{7C4E77C9-6B17-4B02-82C1-DB62EEE2635B}"
Expand Down Expand Up @@ -379,11 +380,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ParallelNoQuantization", "P
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DiscriminativePreTraining", "DiscriminativePreTraining", "{39B9BB97-D0E8-439A-8A1B-8DB8E7CF73C3}"
ProjectSection(SolutionItems) = preProject
Tests\Speech\DNN\DiscriminativePreTraining\add_layer.mel = Tests\Speech\DNN\DiscriminativePreTraining\add_layer.mel
Tests\Speech\DNN\DiscriminativePreTraining\baseline.cpu.txt = Tests\Speech\DNN\DiscriminativePreTraining\baseline.cpu.txt
Tests\Speech\DNN\DiscriminativePreTraining\baseline.gpu.txt = Tests\Speech\DNN\DiscriminativePreTraining\baseline.gpu.txt
Tests\Speech\DNN\DiscriminativePreTraining\baseline.windows.cpu.txt = Tests\Speech\DNN\DiscriminativePreTraining\baseline.windows.cpu.txt
Tests\Speech\DNN\DiscriminativePreTraining\baseline.windows.gpu.txt = Tests\Speech\DNN\DiscriminativePreTraining\baseline.windows.gpu.txt
Tests\Speech\DNN\DiscriminativePreTraining\cntk_dpt.config = Tests\Speech\DNN\DiscriminativePreTraining\cntk_dpt.config
Tests\Speech\DNN\DiscriminativePreTraining\dnn.txt = Tests\Speech\DNN\DiscriminativePreTraining\dnn.txt
Tests\Speech\DNN\DiscriminativePreTraining\dnn_1layer.txt = Tests\Speech\DNN\DiscriminativePreTraining\dnn_1layer.txt
Tests\Speech\DNN\DiscriminativePreTraining\macros.txt = Tests\Speech\DNN\DiscriminativePreTraining\macros.txt
Tests\Speech\DNN\DiscriminativePreTraining\run-test = Tests\Speech\DNN\DiscriminativePreTraining\run-test
Tests\Speech\DNN\DiscriminativePreTraining\testcases.yml = Tests\Speech\DNN\DiscriminativePreTraining\testcases.yml
EndProjectSection
Expand Down Expand Up @@ -413,6 +418,44 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UCIFastReaderTests", "Tests
{E6646FFE-3588-4276-8A15-8D65C22711C1} = {E6646FFE-3588-4276-8A15-8D65C22711C1}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SequenceTraining", "SequenceTraining", "{BB8B9FC5-C4B3-477F-80E2-665DC8E431BD}"
ProjectSection(SolutionItems) = preProject
Tests\Speech\DNN\SequenceTraining\add_layer.mel = Tests\Speech\DNN\SequenceTraining\add_layer.mel
Tests\Speech\DNN\SequenceTraining\baseline.gpu.txt = Tests\Speech\DNN\SequenceTraining\baseline.gpu.txt
Tests\Speech\DNN\SequenceTraining\baseline.windows.gpu.txt = Tests\Speech\DNN\SequenceTraining\baseline.windows.gpu.txt
Tests\Speech\DNN\SequenceTraining\cntk_sequence.config = Tests\Speech\DNN\SequenceTraining\cntk_sequence.config
Tests\Speech\DNN\SequenceTraining\dnn.txt = Tests\Speech\DNN\SequenceTraining\dnn.txt
Tests\Speech\DNN\SequenceTraining\dnn_1layer.txt = Tests\Speech\DNN\SequenceTraining\dnn_1layer.txt
Tests\Speech\DNN\SequenceTraining\macros.txt = Tests\Speech\DNN\SequenceTraining\macros.txt
Tests\Speech\DNN\SequenceTraining\replace_ce_with_sequence_criterion.mel = Tests\Speech\DNN\SequenceTraining\replace_ce_with_sequence_criterion.mel
Tests\Speech\DNN\SequenceTraining\run-test = Tests\Speech\DNN\SequenceTraining\run-test
Tests\Speech\DNN\SequenceTraining\testcases.yml = Tests\Speech\DNN\SequenceTraining\testcases.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Image", "Image", "{8071EF60-30F7-4A77-81AA-ADCA0E18B1E3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Data", "Data", "{76F9323D-34A1-43A5-A594-C4798931FF21}"
ProjectSection(SolutionItems) = preProject
Tests\Image\Data\labelsmap.txt = Tests\Image\Data\labelsmap.txt
Tests\Image\Data\Test.txt = Tests\Image\Data\Test.txt
Tests\Image\Data\Train.txt = Tests\Image\Data\Train.txt
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "QuickE2E", "QuickE2E", "{2A884EB5-037C-481E-8170-BCDC8B3EDD93}"
ProjectSection(SolutionItems) = preProject
Tests\Image\QuickE2E\baseline.linux.debug.gpu.txt = Tests\Image\QuickE2E\baseline.linux.debug.gpu.txt
Tests\Image\QuickE2E\baseline.linux.release.gpu.txt = Tests\Image\QuickE2E\baseline.linux.release.gpu.txt
Tests\Image\QuickE2E\baseline.windows.debug.cpu.txt = Tests\Image\QuickE2E\baseline.windows.debug.cpu.txt
Tests\Image\QuickE2E\baseline.windows.debug.gpu.txt = Tests\Image\QuickE2E\baseline.windows.debug.gpu.txt
Tests\Image\QuickE2E\baseline.windows.release.cpu.txt = Tests\Image\QuickE2E\baseline.windows.release.cpu.txt
Tests\Image\QuickE2E\baseline.windows.release.gpu.txt = Tests\Image\QuickE2E\baseline.windows.release.gpu.txt
Tests\Image\QuickE2E\cntk.config = Tests\Image\QuickE2E\cntk.config
Tests\Image\QuickE2E\Convolution.ndl = Tests\Image\QuickE2E\Convolution.ndl
Tests\Image\QuickE2E\Macros.ndl = Tests\Image\QuickE2E\Macros.ndl
Tests\Image\QuickE2E\run-test = Tests\Image\QuickE2E\run-test
Tests\Image\QuickE2E\testcases.yml = Tests\Image\QuickE2E\testcases.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
Expand Down Expand Up @@ -699,5 +742,9 @@ Global
{4701E678-5E6F-470D-B348-9CD1A2C095D1} = {6F19321A-65E7-4829-B00C-3886CD6C6EDE}
{EB2BE26F-6BD4-4274-971F-86D080779DD1} = {DD043083-71A4-409A-AA91-F9C548DCF7EC}
{B97BDF88-F6B5-4F3A-BD8E-45F787D0C3C3} = {6F19321A-65E7-4829-B00C-3886CD6C6EDE}
{BB8B9FC5-C4B3-477F-80E2-665DC8E431BD} = {6994C86D-A672-4254-824A-51F4DFEB807F}
{8071EF60-30F7-4A77-81AA-ADCA0E18B1E3} = {D45DF403-6781-444E-B654-A96868C5BE68}
{76F9323D-34A1-43A5-A594-C4798931FF21} = {8071EF60-30F7-4A77-81AA-ADCA0E18B1E3}
{2A884EB5-037C-481E-8170-BCDC8B3EDD93} = {8071EF60-30F7-4A77-81AA-ADCA0E18B1E3}
EndGlobalSection
EndGlobal
56 changes: 33 additions & 23 deletions Common/BestGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,39 @@ class BestGpu
static const int RequeryDevices = -2; // Requery refreshing statistics and picking the same number as last query
std::vector<int> GetDevices(int number = AllDevices, BestGpuFlags flags = bestGpuNormal ); // get multiple devices
private:
bool LockDevice(int deviceID, bool trial = true);
bool LockDevice(int deviceId, bool trial = true);
};

// DeviceFromConfig - Parse 'deviceId' config parameter to determine what type of behavior is desired
//Symbol - Meaning
// 'auto' - automatically pick a single GPU based on ?BestGpu? score
// 'cpu' - use the CPU
// 0 - or some other single number, use a single GPU with CUDA ID same as the number
// This can only be called with the same parameters each time, and 'auto' is determined upon first call.
static DEVICEID_TYPE SelectDevice(DEVICEID_TYPE deviceId, bool bLockGPU)
{
//recommend to use CPU. Adding -1 for backward compatability
// This can only be called with the same parameter.
static DEVICEID_TYPE lastDeviceId = DEVICEID_NOTYETDETERMINED;
if (lastDeviceId == DEVICEID_NOTYETDETERMINED)
lastDeviceId = deviceId;
else if (lastDeviceId != deviceId)
InvalidArgument("SelectDevice: Attempted to change device selection from %d to %d (%d means 'auto').", (int)lastDeviceId, (int)deviceId, (int)DEVICEID_AUTO);

if (deviceId == DEVICEID_AUTO)
{
// GPU device to be auto-selected, so init our class
static BestGpu* g_bestGpu = nullptr;
if (g_bestGpu == nullptr)
g_bestGpu = new BestGpu();
deviceId = (DEVICEID_TYPE)
g_bestGpu->GetDevice(BestGpuFlags(bLockGPU ? (bestGpuAvoidSharing | bestGpuExclusiveLock) : bestGpuAvoidSharing));
static DEVICEID_TYPE bestDeviceId = DEVICEID_NOTYETDETERMINED;
if (bestDeviceId == DEVICEID_NOTYETDETERMINED) // we only choose once
{
// GPU device to be auto-selected, so init our class
static BestGpu* g_bestGpu = nullptr;
if (g_bestGpu == nullptr)
g_bestGpu = new BestGpu();
deviceId = (DEVICEID_TYPE)
g_bestGpu->GetDevice(BestGpuFlags(bLockGPU ? (bestGpuAvoidSharing | bestGpuExclusiveLock) : bestGpuAvoidSharing));
bestDeviceId = deviceId;
}
else // already chosen
deviceId = bestDeviceId;
}
// route the result through EnforceOneGPUOnly() which only lets the first choice through (see comment there)
return EnforceOneGPUOnly(deviceId);
Expand All @@ -141,9 +155,7 @@ static DEVICEID_TYPE SelectDevice(DEVICEID_TYPE deviceId, bool bLockGPU)
//#endif
DEVICEID_TYPE DeviceFromConfig(const ScriptableObjects::IConfigRecord & config)
{
static DEVICEID_TYPE deviceId = CPUDEVICE;

bool bLockGPU = config(L"LockGPU", true);
bool bLockGPU = config(L"lockGPU", true);
// we need to deal with the old CNTK config semantics where 'deviceId' can be either a string or an int
auto valpp = config.Find(L"deviceId");
if (!valpp)
Expand All @@ -168,10 +180,8 @@ DEVICEID_TYPE DeviceFromConfig(const ScriptableObjects::IConfigRecord & config)
//#endif
DEVICEID_TYPE DeviceFromConfig(const ConfigParameters& config)
{
static DEVICEID_TYPE deviceId = CPUDEVICE;

ConfigValue val = config("deviceId", "auto");
bool bLockGPU = config(L"LockGPU", true);
bool bLockGPU = config(L"lockGPU", true);

if (!_stricmp(val.c_str(), "cpu"))
return SelectDevice(CPUDEVICE, false);
Expand Down Expand Up @@ -258,7 +268,7 @@ void BestGpu::Init()
{
const char* errmsg = cudaGetErrorString(err);
fprintf(stderr, "!!!!!!!!CUDA EXCEPTION: %s\n", errmsg);
RuntimeError(errmsg);
RuntimeError("%s", errmsg);
}

ProcessorData pdEmpty = { 0 };
Expand Down Expand Up @@ -602,28 +612,28 @@ void BestGpu::QueryNvmlData()
return;
}

bool BestGpu::LockDevice(int deviceID, bool trial)
bool BestGpu::LockDevice(int deviceId, bool trial)
{
if (deviceID < 0) // don't lock CPU, always return true
if (deviceId < 0) // don't lock CPU, always return true
{
return true;
}
// ported from dbn.exe, not perfect but it works in practice
char buffer[80];
sprintf (buffer, "DBN.exe GPGPU exclusive lock for device %d", deviceID);
sprintf (buffer, "DBN.exe GPGPU exclusive lock for device %d", deviceId);
std::unique_ptr<CrossProcessMutex> mutex(new CrossProcessMutex(buffer));
if (!mutex->Acquire(false)) // failure --this should not really happen
{
fprintf(stderr, "LockDevice: can't lock the device %d\n", deviceID);
fprintf(stderr, "LockDevice: Failed to lock GPU %d for exclusive use.\n", deviceId);
return false;
}
else
{
fprintf(stderr, "LockDevice: Capture device %d and lock it for exclusive use\n", deviceID);
fprintf(stderr, "LockDevice: Locked GPU %d %s.\n", deviceId, trial ? "to test availability" : "for exclusive use");
if (!trial)
{
m_GPUMutex[deviceID] = std::move(mutex);
}
m_GPUMutex[deviceId] = std::move(mutex);
else
fprintf(stderr, "LockDevice: Unlocked GPU %d after testing.\n", deviceId);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/CheckInSuites/MNIST/DefaultMacros.ndl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#Base feed Forward network, defines Bias and wieght parameters
BFF(in, rows, cols)
{
B=Parameter(rows, init=fixedvalue, value=0)
B=Parameter(rows, init="fixedValue", value=0)
W=Parameter(rows, cols)
FF = FF(in, w, b)
}
Expand Down
Loading

0 comments on commit 7e05bb7

Please sign in to comment.