2021-02-01 13:31:45 +01:00
|
|
|
/* ******************************************************************************
|
|
|
|
*
|
2019-06-06 14:21:15 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2021-02-01 13:31:45 +01:00
|
|
|
* See the NOTICE file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2019-06-06 14:21:15 +02:00
|
|
|
* 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>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/dll.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <array/DataType.h>
|
|
|
|
#include <types/pair.h>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/pointercast.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd{
|
2019-06-06 14:21:15 +02:00
|
|
|
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;
|
2020-03-02 10:49:41 +01:00
|
|
|
std::atomic<sd::DataType> _dataType;
|
2019-06-06 14:21:15 +02:00
|
|
|
std::atomic<bool> _precBoost;
|
|
|
|
std::atomic<bool> _useMKLDNN{true};
|
2019-11-14 12:35:02 +01:00
|
|
|
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
|
|
|
|
2020-03-05 12:11:13 +01:00
|
|
|
bool _blasFallback = false;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
Environment();
|
|
|
|
public:
|
2020-06-06 14:26:55 +02:00
|
|
|
~Environment();
|
2019-09-04 13:41:08 +02:00
|
|
|
/**
|
|
|
|
* These 3 fields are mostly for CUDA/cuBLAS version tracking
|
|
|
|
*/
|
|
|
|
int _blasMajorVersion = 0;
|
|
|
|
int _blasMinorVersion = 0;
|
|
|
|
int _blasPatchVersion = 0;
|
|
|
|
|
2020-06-06 14:26:55 +02:00
|
|
|
static Environment& getInstance();
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
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);
|
2019-11-14 12:35:02 +01:00
|
|
|
bool helpersAllowed();
|
|
|
|
void allowHelpers(bool reallyAllow);
|
2020-03-05 12:11:13 +01:00
|
|
|
|
|
|
|
bool blasFallback();
|
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);
|
|
|
|
|
2019-11-14 12:35:02 +01:00
|
|
|
int maxMasterThreads();
|
|
|
|
void setMaxMasterThreads(int max);
|
|
|
|
|
2020-01-24 08:11:09 +01:00
|
|
|
/*
|
|
|
|
* Legacy memory limits API, still used in new API as simplified version
|
|
|
|
*/
|
2019-11-14 12:35:02 +01:00
|
|
|
void setMaxPrimaryMemory(uint64_t maxBytes);
|
|
|
|
void setMaxSpecialyMemory(uint64_t maxBytes);
|
|
|
|
void setMaxDeviceMemory(uint64_t maxBytes);
|
|
|
|
|
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); }
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
sd::DataType defaultFloatDataType();
|
|
|
|
void setDefaultFloatDataType(sd::DataType dtype);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
bool precisionBoostAllowed();
|
|
|
|
void allowPrecisionBoost(bool reallyAllow);
|
|
|
|
|
|
|
|
bool isExperimentalBuild();
|
|
|
|
|
|
|
|
bool isCPU();
|
|
|
|
|
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
|