cavis/libnd4j/blas/Environment.h

148 lines
4.3 KiB
C
Raw Normal View History

2019-06-06 14:21:15 +02:00
/*******************************************************************************
* Copyright (c) 2015-2018 Skymind, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
//
// Created by raver119 on 06.10.2017.
//
#ifndef LIBND4J_ENVIRONMENT_H
#define LIBND4J_ENVIRONMENT_H
#include <atomic>
#include <vector>
#include <dll.h>
#include <stdexcept>
#include <array/DataType.h>
#include <types/pair.h>
[WIP] Memory limits (#167) * initial commit Signed-off-by: raver119 <raver119@gmail.com> * one more initial commit Signed-off-by: raver119 <raver119@gmail.com> * additional initial commit Signed-off-by: raver119 <raver119@gmail.com> * subsequent initial commit Signed-off-by: raver119 <raver119@gmail.com> * initial commit testing Signed-off-by: raver119 <raver119@gmail.com> * initial commit per device Signed-off-by: raver119 <raver119@gmail.com> * initial commit per group Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda + few missed lines Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda + missed includes Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda + one more missed include Signed-off-by: raver119 <raver119@gmail.com> * initial commit shouldn't count host mem as dev0 in cuda Signed-off-by: raver119 <raver119@gmail.com> * initial commit that tracks HOST group limits for CUDA Signed-off-by: raver119 <raver119@gmail.com> * initial commit with some Environment changes Signed-off-by: raver119 <raver119@gmail.com> * initial commit with more Environment changes Signed-off-by: raver119 <raver119@gmail.com> * initial commit with maxMasterThreads fix Signed-off-by: raver119 <raver119@gmail.com> * initial commit with maxMasterThreads fix Signed-off-by: raver119 <raver119@gmail.com> * initial commit without maxMasterThreads exception Signed-off-by: raver119 <raver119@gmail.com> * initial commit without Nd4jULong in Environment Signed-off-by: raver119 <raver119@gmail.com> * add sleep and more iterations for OOM cases Signed-off-by: raver119 <raver119@gmail.com> * limits propagation from java side Signed-off-by: raver119 <raver119@gmail.com> * - consume ErrorCode every time - one test for memory limits Signed-off-by: raver119 <raver119@gmail.com> * unordered_map Signed-off-by: raver119 <raver119@gmail.com> * unordered_map Signed-off-by: raver119 <raver119@gmail.com> * unordered_map Signed-off-by: raver119 <raver119@gmail.com> * RSub op mapping fixed Signed-off-by: raver119 <raver119@gmail.com> * typo fixed Signed-off-by: raver119 <raver119@gmail.com> * one bad test fixed Signed-off-by: raver119 <raver119@gmail.com>
2020-01-24 08:11:09 +01:00
#include <pointercast.h>
2019-06-06 14:21:15 +02:00
namespace nd4j{
class ND4J_EXPORT Environment {
private:
std::atomic<int> _tadThreshold;
std::atomic<int> _elementThreshold;
std::atomic<bool> _verbose;
std::atomic<bool> _debug;
std::atomic<bool> _leaks;
std::atomic<bool> _profile;
std::atomic<nd4j::DataType> _dataType;
std::atomic<bool> _precBoost;
std::atomic<bool> _useMKLDNN{true};
std::atomic<bool> _allowHelpers{true};
std::atomic<int> _maxThreads;
std::atomic<int> _maxMasterThreads;
// these fields hold defaults
std::atomic<int64_t> _maxTotalPrimaryMemory{-1};
std::atomic<int64_t> _maxTotalSpecialMemory{-1};
std::atomic<int64_t> _maxDeviceMemory{-1};
2019-06-06 14:21:15 +02:00
#ifdef __ND4J_EXPERIMENTAL__
const bool _experimental = true;
#else
const bool _experimental = false;
#endif
// device compute capability for CUDA
std::vector<Pair> _capabilities;
static Environment* _instance;
Environment();
~Environment();
public:
/**
* These 3 fields are mostly for CUDA/cuBLAS version tracking
*/
int _blasMajorVersion = 0;
int _blasMinorVersion = 0;
int _blasPatchVersion = 0;
2019-06-06 14:21:15 +02:00
static Environment* getInstance();
bool isVerbose();
void setVerbose(bool reallyVerbose);
bool isDebug();
bool isProfiling();
bool isDetectingLeaks();
bool isDebugAndVerbose();
void setDebug(bool reallyDebug);
void setProfiling(bool reallyProfile);
void setLeaksDetector(bool reallyDetect);
bool helpersAllowed();
void allowHelpers(bool reallyAllow);
2019-06-06 14:21:15 +02:00
int tadThreshold();
void setTadThreshold(int threshold);
int elementwiseThreshold();
void setElementwiseThreshold(int threshold);
int maxThreads();
void setMaxThreads(int max);
int maxMasterThreads();
void setMaxMasterThreads(int max);
[WIP] Memory limits (#167) * initial commit Signed-off-by: raver119 <raver119@gmail.com> * one more initial commit Signed-off-by: raver119 <raver119@gmail.com> * additional initial commit Signed-off-by: raver119 <raver119@gmail.com> * subsequent initial commit Signed-off-by: raver119 <raver119@gmail.com> * initial commit testing Signed-off-by: raver119 <raver119@gmail.com> * initial commit per device Signed-off-by: raver119 <raver119@gmail.com> * initial commit per group Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda + few missed lines Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda + missed includes Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda + one more missed include Signed-off-by: raver119 <raver119@gmail.com> * initial commit shouldn't count host mem as dev0 in cuda Signed-off-by: raver119 <raver119@gmail.com> * initial commit that tracks HOST group limits for CUDA Signed-off-by: raver119 <raver119@gmail.com> * initial commit with some Environment changes Signed-off-by: raver119 <raver119@gmail.com> * initial commit with more Environment changes Signed-off-by: raver119 <raver119@gmail.com> * initial commit with maxMasterThreads fix Signed-off-by: raver119 <raver119@gmail.com> * initial commit with maxMasterThreads fix Signed-off-by: raver119 <raver119@gmail.com> * initial commit without maxMasterThreads exception Signed-off-by: raver119 <raver119@gmail.com> * initial commit without Nd4jULong in Environment Signed-off-by: raver119 <raver119@gmail.com> * add sleep and more iterations for OOM cases Signed-off-by: raver119 <raver119@gmail.com> * limits propagation from java side Signed-off-by: raver119 <raver119@gmail.com> * - consume ErrorCode every time - one test for memory limits Signed-off-by: raver119 <raver119@gmail.com> * unordered_map Signed-off-by: raver119 <raver119@gmail.com> * unordered_map Signed-off-by: raver119 <raver119@gmail.com> * unordered_map Signed-off-by: raver119 <raver119@gmail.com> * RSub op mapping fixed Signed-off-by: raver119 <raver119@gmail.com> * typo fixed Signed-off-by: raver119 <raver119@gmail.com> * one bad test fixed Signed-off-by: raver119 <raver119@gmail.com>
2020-01-24 08:11:09 +01:00
/*
* Legacy memory limits API, still used in new API as simplified version
*/
void setMaxPrimaryMemory(uint64_t maxBytes);
void setMaxSpecialyMemory(uint64_t maxBytes);
void setMaxDeviceMemory(uint64_t maxBytes);
[WIP] Memory limits (#167) * initial commit Signed-off-by: raver119 <raver119@gmail.com> * one more initial commit Signed-off-by: raver119 <raver119@gmail.com> * additional initial commit Signed-off-by: raver119 <raver119@gmail.com> * subsequent initial commit Signed-off-by: raver119 <raver119@gmail.com> * initial commit testing Signed-off-by: raver119 <raver119@gmail.com> * initial commit per device Signed-off-by: raver119 <raver119@gmail.com> * initial commit per group Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda + few missed lines Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda + missed includes Signed-off-by: raver119 <raver119@gmail.com> * initial commit for cuda + one more missed include Signed-off-by: raver119 <raver119@gmail.com> * initial commit shouldn't count host mem as dev0 in cuda Signed-off-by: raver119 <raver119@gmail.com> * initial commit that tracks HOST group limits for CUDA Signed-off-by: raver119 <raver119@gmail.com> * initial commit with some Environment changes Signed-off-by: raver119 <raver119@gmail.com> * initial commit with more Environment changes Signed-off-by: raver119 <raver119@gmail.com> * initial commit with maxMasterThreads fix Signed-off-by: raver119 <raver119@gmail.com> * initial commit with maxMasterThreads fix Signed-off-by: raver119 <raver119@gmail.com> * initial commit without maxMasterThreads exception Signed-off-by: raver119 <raver119@gmail.com> * initial commit without Nd4jULong in Environment Signed-off-by: raver119 <raver119@gmail.com> * add sleep and more iterations for OOM cases Signed-off-by: raver119 <raver119@gmail.com> * limits propagation from java side Signed-off-by: raver119 <raver119@gmail.com> * - consume ErrorCode every time - one test for memory limits Signed-off-by: raver119 <raver119@gmail.com> * unordered_map Signed-off-by: raver119 <raver119@gmail.com> * unordered_map Signed-off-by: raver119 <raver119@gmail.com> * unordered_map Signed-off-by: raver119 <raver119@gmail.com> * RSub op mapping fixed Signed-off-by: raver119 <raver119@gmail.com> * typo fixed Signed-off-by: raver119 <raver119@gmail.com> * one bad test fixed Signed-off-by: raver119 <raver119@gmail.com>
2020-01-24 08:11:09 +01:00
uint64_t maxPrimaryMemory();
uint64_t maxSpecialMemory();
////////////////////////
/*
* Methods for memory limits/counters
*/
void setGroupLimit(int group, Nd4jLong numBytes);
void setDeviceLimit(int deviceId, Nd4jLong numBytes);
Nd4jLong getGroupLimit(int group);
Nd4jLong getDeviceLimit(int deviceId);
Nd4jLong getGroupCounter(int group);
Nd4jLong getDeviceCounter(int deviceId);
////////////////////////
2019-06-06 14:21:15 +02:00
bool isUseMKLDNN() { return _useMKLDNN.load(); }
void setUseMKLDNN(bool useMKLDNN) { _useMKLDNN.store(useMKLDNN); }
nd4j::DataType defaultFloatDataType();
void setDefaultFloatDataType(nd4j::DataType dtype);
bool precisionBoostAllowed();
void allowPrecisionBoost(bool reallyAllow);
bool isExperimentalBuild();
bool isCPU();
SameDiff cleanup and fixes (#12) * #8160 Remove resolvePrepertiesFromSameDiffBeforeExecution Signed-off-by: AlexDBlack <blacka101@gmail.com> * SameDiff API cleanup Signed-off-by: AlexDBlack <blacka101@gmail.com> * More SameDiff cleanup Signed-off-by: AlexDBlack <blacka101@gmail.com> * Small fixes Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8248 Switch SameDiff variable init from lazy to creation time for more predictable behaviour Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8252 TanhDerivative javadoc Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8225 Deconvolution2D input validation Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8265 Switch SameDiff.outputs() to user settable, instead of unreliable 'best guess' Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8224 SameDiff.zero and .one create constants, not variables Signed-off-by: AlexDBlack <blacka101@gmail.com> * More cleanup and fixes Signed-off-by: AlexDBlack <blacka101@gmail.com> * Small test fix Signed-off-by: AlexDBlack <blacka101@gmail.com> * Small fix Signed-off-by: AlexDBlack <blacka101@gmail.com> * DL4J SameDiff fixes Signed-off-by: AlexDBlack <blacka101@gmail.com> * Re-add hack for Deconvolution2DLayer until #8315 is resolved Signed-off-by: AlexDBlack <blacka101@gmail.com> * #8270 Move CUDA device/version logging to Java; can be disabled via existing org.nd4j.log.initialization system property Signed-off-by: AlexDBlack <blacka101@gmail.com> * All ND4J init logging checks system property Signed-off-by: AlexDBlack <blacka101@gmail.com> * Small tweak Signed-off-by: AlexDBlack <blacka101@gmail.com> * Remove redundant device logging Signed-off-by: AlexDBlack <blacka101@gmail.com> * One more fix Signed-off-by: AlexDBlack <blacka101@gmail.com> * UX improvements Signed-off-by: AlexDBlack <blacka101@gmail.com> * Deconv fix Signed-off-by: AlexDBlack <blacka101@gmail.com> * Add deconv tests Signed-off-by: AlexDBlack <blacka101@gmail.com> * Cleanup Signed-off-by: AlexDBlack <blacka101@gmail.com> * Remove debug code Signed-off-by: AlexDBlack <blacka101@gmail.com>
2019-10-26 03:38:08 +02:00
int blasMajorVersion();
int blasMinorVersion();
int blasPatchVersion();
2019-06-06 14:21:15 +02:00
std::vector<Pair>& capabilities();
};
}
#endif //LIBND4J_ENVIRONMENT_H