https://github.com/Microsoft/CNTK
Raw File
Tip revision: 5d30b06636e6bdd3d99abc7adedfcfc842811776 authored by Ivan Stojiljkovic on 19 December 2016, 10:12:15 UTC
Address CR feedback
Tip revision: 5d30b06
Globals.h
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
//

#pragma once

#include <atomic>

namespace Microsoft { namespace MSR { namespace CNTK {

    // Class containing global configuration for CNTK.
    class Globals
    {
    public:
        static void       ForceDeterministicAlgorithms() {        m_forceDeterministicAlgorithms = true; }
        static bool ShouldForceDeterministicAlgorithms() { return m_forceDeterministicAlgorithms; }

        static void       ForceConstantRandomSeed() {        m_forceConstantRandomSeed = true; }
        static bool ShouldForceConstantRandomSeed() { return m_forceConstantRandomSeed; }

        static void EnableGradientAccumulationOptimization() { m_optimizeGradientAccumulation = true; }
        static void DisableGradientAccumulationOptimization() { m_optimizeGradientAccumulation = false; }
        static bool ShouldOptimizeGradientAccumulation() { return m_optimizeGradientAccumulation; }

        // TODO: Currently the flag is set to false. Should be switched to true after more rigorous testing.
        static bool UseV2Aggregator() { return false; }

        static void EnableShareNodeValueMatrices()
        {
            m_enableShareNodeValueMatrices = true;
        }

        static bool ShouldEnableShareNodeValueMatrices()
        {
            return m_enableShareNodeValueMatrices;
        }

        static void EnableHyperCompressMemory()
        {
            m_enableHyperCompressMemory = true;
        }

        static bool ShouldEnableHyperCompressMemory()
        {
            return m_enableHyperCompressMemory;
        }

    private:
        static std::atomic<bool> m_forceDeterministicAlgorithms;
        // The global flag to enable matrices values in forward and backward prop
        static std::atomic<bool> m_enableShareNodeValueMatrices;
        // The global flag to enable hyper memory compression 
        static std::atomic<bool> m_enableHyperCompressMemory;
        static std::atomic<bool> m_forceConstantRandomSeed;
        static std::atomic<bool> m_optimizeGradientAccumulation;
    };
}}}
back to top