Skip to content

Commit

Permalink
Fixing compilation of CPUMatrix on Windows: heap overflow fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
eldakms committed Apr 19, 2017
1 parent aa47f38 commit ed2f973
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ MATH_SRC =\
$(SOURCEDIR)/Math/BatchNormalizationEngine.cpp \
$(SOURCEDIR)/Math/BlockHandlerSSE.cpp \
$(SOURCEDIR)/Math/CUDAPageLockedMemAllocator.cpp \
$(SOURCEDIR)/Math/CPUMatrix.cpp \
$(SOURCEDIR)/Math/CPUMatrixFloat.cpp \
$(SOURCEDIR)/Math/CPUMatrixDouble.cpp \
$(SOURCEDIR)/Math/CPURNGHandle.cpp \
$(SOURCEDIR)/Math/CPUSparseMatrix.cpp \
$(SOURCEDIR)/Math/ConvolutionEngine.cpp \
Expand Down
12 changes: 12 additions & 0 deletions Source/Math/CPUMatrixDouble.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
//
#include "stdafx.h"
#include "CPUMatrixImpl.h"

namespace Microsoft { namespace MSR { namespace CNTK {

// explicit instantiations, due to CPUMatrix being too big and causing VS2015 cl crash.
template class MATH_API CPUMatrix<double>;
}}}
24 changes: 24 additions & 0 deletions Source/Math/CPUMatrixFloat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
//
#include "stdafx.h"
#include "CPUMatrixImpl.h"

namespace Microsoft { namespace MSR { namespace CNTK {

int MATH_API TracingGPUMemoryAllocator::m_traceLevel = 0;

void TracingGPUMemoryAllocator::SetTraceLevel(int traceLevel)
{
m_traceLevel = traceLevel;
}

bool TracingGPUMemoryAllocator::IsTraceEnabled()
{
return (m_traceLevel > 0);
}

// explicit instantiations, due to CPUMatrix being too big and causing VS2015 cl crash.
template class MATH_API CPUMatrix<float>;
}}}
25 changes: 4 additions & 21 deletions Source/Math/CPUMatrix.cpp → Source/Math/CPUMatrixImpl.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
//
// CPUMatrix.cpp : full implementation of all matrix functions on the CPU side
// CPUMatrix.h : template implementation of all matrix functions on the CPU side
//

#include "stdafx.h"
#pragma once

#include "Basics.h"
#include "File.h"

Expand Down Expand Up @@ -66,18 +67,6 @@
#define IDX2C(i, j, ld) (((j) * (ld)) + (i)) // 0 based indexing
namespace Microsoft { namespace MSR { namespace CNTK {

int MATH_API TracingGPUMemoryAllocator::m_traceLevel = 0;

void TracingGPUMemoryAllocator::SetTraceLevel(int traceLevel)
{
m_traceLevel = traceLevel;
}

bool TracingGPUMemoryAllocator::IsTraceEnabled()
{
return (m_traceLevel > 0);
}

#pragma region Helpful Enum Definitions
enum class MatrixOrder
{
Expand Down Expand Up @@ -5923,7 +5912,7 @@ CPUMatrix<ElemType>& CPUMatrix<ElemType>::AssignElementProductOfWithShift(const
#pragma endregion Static BLAS Functions

// 'double' version of LogAdd
double LogAddD(double x, double y)
inline double LogAddD(double x, double y)
{
return LogAdd(x, y);
}
Expand Down Expand Up @@ -7184,12 +7173,6 @@ void CPUMatrix<ElemType>::TensorArgOp(const CPUMatrix<ElemType>& a, ElementWiseO
}
}

// =======================================================================
// explicit instantiations
// =======================================================================
template class MATH_API CPUMatrix<float>;
template class MATH_API CPUMatrix<double>;

// We use Matrix<char> as the backing store for QuantizedMatrix
// Let's explicitly instantiate the methods we need for that purpose
template CPUMatrix<char>::CPUMatrix(const size_t numRows, const size_t numCols);
Expand Down
6 changes: 4 additions & 2 deletions Source/Math/Math.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,15 @@
<ClInclude Include="QuantizedMatrix.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="CPUMatrixImpl.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="BatchNormalizationEngine.cpp" />
<ClCompile Include="BlockHandlerAVX.cpp" />
<ClCompile Include="BlockHandlerSSE.cpp" />
<ClCompile Include="ConvolutionEngine.cpp" />
<ClCompile Include="CPUMatrixDouble.cpp" />
<ClCompile Include="CPUMatrixFloat.cpp" />
<ClCompile Include="CPURNGHandle.cpp" />
<ClCompile Include="CPUSparseMatrix.cpp" />
<ClCompile Include="CUDAPageLockedMemAllocator.cpp" />
Expand All @@ -209,7 +212,6 @@
<PrecompiledHeader>
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="CPUMatrix.cpp" />
<ClCompile Include="MatrixQuantizerCPU.cpp" />
<ClCompile Include="MatrixQuantizerImpl.cpp" />
<ClCompile Include="NoGPU.cpp" />
Expand All @@ -231,4 +233,4 @@
<Error Condition="'$(MathLibrary)' == 'MKL' And !Exists('$(CNTKCustomMKLPath)')" Text="CNTK custom MKL version $(CNTKCustomMKLVersion) not found. See https://github.com/Microsoft/CNTK/wiki/Setup-CNTK-on-Windows#mkl for instructions." />
<Error Condition="!$(HasBoost)" Text="The Boost library is required to build. Please see https://github.com/Microsoft/CNTK/wiki/Setup-CNTK-on-Windows#boost for installation instructions." />
</Target>
</Project>
</Project>
12 changes: 9 additions & 3 deletions Source/Math/Math.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="Matrix.cpp" />
<ClCompile Include="CPUMatrix.cpp">
<Filter>CPU</Filter>
</ClCompile>
<ClCompile Include="CPUSparseMatrix.cpp">
<Filter>CPU</Filter>
</ClCompile>
Expand Down Expand Up @@ -49,6 +46,12 @@
<Filter>CPU</Filter>
</ClCompile>
<ClCompile Include="DataTransferer.cpp" />
<ClCompile Include="CPUMatrixDouble.cpp">
<Filter>CPU</Filter>
</ClCompile>
<ClCompile Include="CPUMatrixFloat.cpp">
<Filter>CPU</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CommonMatrix.h" />
Expand Down Expand Up @@ -131,6 +134,9 @@
<ClInclude Include="QuantizedOperations.h" />
<ClInclude Include="BlockMultiplierMatrixUtil.h" />
<ClInclude Include="DataTransferer.h" />
<ClInclude Include="CPUMatrixImpl.h">
<Filter>CPU</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="GPUMatrix.h">
Expand Down

0 comments on commit ed2f973

Please sign in to comment.