chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:47:05 +08:00
commit 4f3b7da785
7394 changed files with 2005594 additions and 0 deletions
@@ -0,0 +1,119 @@
/* ******************************************************************************
*
*
* 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.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* 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
******************************************************************************/
//
// @author raver119@gmail.com
//
#include <exceptions/cuda_exception.h>
#include <execution/AffinityManager.h>
#include <execution/LaunchContext.h>
#include <helpers/logger.h>
thread_local int globalThreadToDevice = -1;
namespace sd {
std::mutex AffinityManager::_currentMutex;
std::mutex AffinityManager::_numberMutex;
int AffinityManager::_numberOfDevices = -1;
int AffinityManager::currentDeviceId() {
// if there's no affinity set - set it now
if (globalThreadToDevice < 0) {
// this block must be thread-local
_currentMutex.lock();
globalThreadToDevice = _lastDevice++;
// we need to check if we've got deviceId >= number of actual devices, and reset to zero otherwise
if (globalThreadToDevice >= numberOfDevices()) {
globalThreadToDevice = 0;
_lastDevice = numberOfDevices() > 1 ? 1 : 0;
}
_currentMutex.unlock();
setCurrentNativeDevice(globalThreadToDevice);
}
// if we already know affinity - just return it
if (globalThreadToDevice >= 0) return globalThreadToDevice;
int dev = 0;
auto res = cudaGetDevice(&dev);
if (res != 0) throw cuda_exception::build("cudaGetDevice failed", res);
return dev;
}
int AffinityManager::currentNativeDeviceId() {
int dev = 0;
auto res = cudaGetDevice(&dev);
if (res != 0) throw cuda_exception::build("cudaGetDevice failed", res);
return dev;
}
int AffinityManager::numberOfDevices() {
_numberMutex.lock();
// we want to cache number of devices
if (_numberOfDevices <= 0) {
int dev = 0;
auto res = cudaGetDeviceCount(&dev);
if (res != 0) throw cuda_exception::build("cudaGetDeviceCount failed", res);
_numberOfDevices = dev;
}
_numberMutex.unlock();
return _numberOfDevices;
}
void AffinityManager::setCurrentNativeDevice(int deviceId) {
auto res = cudaSetDevice(deviceId);
if (res != 0) throw cuda_exception::build("setCurrentDevice failed", res);
}
void AffinityManager::setCurrentDevice(int deviceId) {
auto previousDeviceId = globalThreadToDevice;
if (previousDeviceId >= 0 && LaunchContext::isInitialized()) {
auto res = cudaStreamSynchronize(*LaunchContext::defaultContext()->getCudaStream());
if (res != 0) throw cuda_exception::build("setCurrentDevice -> sync failed", res);
res = cudaStreamSynchronize(*LaunchContext::defaultContext()->getCudaSpecialStream());
if (res != 0) throw cuda_exception::build("setCurrentDevice -> specialSync failed", res);
if (deviceId != previousDeviceId) {
// discard existing stuff
LaunchContext::releaseBuffers();
}
}
if (deviceId != previousDeviceId) {
auto res = cudaSetDevice(deviceId);
if (res != 0) throw cuda_exception::build("cudaSetDevice failed", res);
}
// update thread-device affinity
globalThreadToDevice = deviceId;
}
std::atomic<int> AffinityManager::_lastDevice; // = std::atomic<int>(initialV);
} // namespace sd
@@ -0,0 +1,202 @@
/* ******************************************************************************
*
*
* 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.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* 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
******************************************************************************/
//
// @author raver119@gmail.com
//
#include <cuda.h>
#include <cuda_device_runtime_api.h>
#include <cuda_runtime.h>
#include <cuda_runtime_api.h>
#include <exceptions/cuda_exception.h>
#include <execution/AffinityManager.h>
#include <execution/ContextBuffers.h>
#include <helpers/logger.h>
namespace sd {
ContextBuffers::ContextBuffers() {
_deviceId = AffinityManager::currentDeviceId();
}
ContextBuffers::ContextBuffers(const ContextBuffers& other) {
release();
this->_initialized = other._initialized;
this->_allocated = other._allocated;
this->_deviceId = other._deviceId;
this->_specialStream = other._specialStream;
this->_execStream = other._execStream;
this->_allocationPointer = other._allocationPointer;
this->_reductionPointer = other._reductionPointer;
this->_scalarPointer = other._scalarPointer;
}
ContextBuffers& ContextBuffers::operator=(const ContextBuffers& other) {
release();
this->_initialized = other._initialized;
this->_allocated = other._allocated;
this->_deviceId = other._deviceId;
this->_specialStream = other._specialStream;
this->_execStream = other._execStream;
this->_allocationPointer = other._allocationPointer;
this->_reductionPointer = other._reductionPointer;
this->_scalarPointer = other._scalarPointer;
return *this;
}
ContextBuffers& ContextBuffers::operator=(ContextBuffers&& other) {
release();
this->_initialized = other._initialized;
this->_allocated = other._allocated;
this->_deviceId = other._deviceId;
this->_specialStream = other._specialStream;
this->_execStream = other._execStream;
this->_allocationPointer = other._allocationPointer;
this->_reductionPointer = other._reductionPointer;
this->_scalarPointer = other._scalarPointer;
return *this;
}
void ContextBuffers::release() {
if (_allocated) {
if (_allocationPointer != nullptr) cudaFree(_allocationPointer);
if (_scalarPointer != nullptr) cudaFreeHost(_scalarPointer);
if (_allocationPointer != nullptr) cudaFree(_reductionPointer);
auto _cudaStream = reinterpret_cast<cudaStream_t*>(_execStream);
auto _cudaSpecialStream = reinterpret_cast<cudaStream_t*>(_specialStream);
cudaStreamSynchronize(*_cudaStream);
cudaStreamSynchronize(*_cudaSpecialStream);
cudaStreamDestroy(*_cudaStream);
cudaStreamDestroy(*_cudaSpecialStream);
delete _cudaStream;
delete _cudaSpecialStream;
//////
_allocated = false;
_deviceId = -1;
this->_specialStream = nullptr;
this->_execStream = nullptr;
this->_allocationPointer = nullptr;
this->_reductionPointer = nullptr;
this->_scalarPointer = nullptr;
}
_initialized = false;
}
ContextBuffers::~ContextBuffers() { release(); }
ContextBuffers::ContextBuffers(void* rPointer, void* sPointer, void* aPointer, bool isOwner) {
_reductionPointer = rPointer;
_scalarPointer = sPointer;
_allocationPointer = aPointer;
_allocated = isOwner;
}
void ContextBuffers::initialize() {
_deviceId = AffinityManager::currentNativeDeviceId();
auto res = cudaMalloc(reinterpret_cast<void**>(&_reductionPointer), 1024 * 1024 * 8);
if (res != 0) throw cuda_exception::build("_reductionPointer allocation failed", res);
res = cudaHostAlloc(reinterpret_cast<void**>(&_scalarPointer), 16, cudaHostAllocDefault);
if (res != 0) throw cuda_exception::build("_scalarPointer allocation failed", res);
res = cudaMalloc(reinterpret_cast<void**>(&_allocationPointer), 1024 * 1024 * 8);
if (res != 0) throw cuda_exception::build("_allocationPointer allocation failed", res);
_execStream = new cudaStream_t();
_specialStream = new cudaStream_t();
if (nullptr == _execStream || nullptr == _specialStream)
THROW_EXCEPTION("Failed to allocate memory for new CUDA stream");
res = cudaStreamCreate(reinterpret_cast<cudaStream_t*>(_execStream));
if (res != 0) throw cuda_exception::build("Failed to create default CUDA stream with launch context", res);
res = cudaStreamCreate(reinterpret_cast<cudaStream_t*>(_specialStream));
if (res != 0) throw cuda_exception::build("Failed to create special CUDA stream with launch context", res);
_allocated = true;
_initialized = true;
}
void* ContextBuffers::reductionBuffer() {
if (!_initialized) initialize();
return _reductionPointer;
}
void* ContextBuffers::scalarBuffer() {
if (!_initialized) initialize();
return _scalarPointer;
}
void* ContextBuffers::allocationBuffer() {
if (!_initialized) initialize();
return _allocationPointer;
}
void ContextBuffers::setReductionBuffer(void* pointer) { _reductionPointer = pointer; }
void ContextBuffers::setScalarBuffer(void* pointer) { _scalarPointer = pointer; }
void ContextBuffers::setAllocationBuffer(void* pointer) { _allocationPointer = pointer; }
void ContextBuffers::triggerOwnership(bool isOwner) { _allocated = isOwner; }
int ContextBuffers::deviceId() { return _deviceId; }
void* ContextBuffers::execStream() {
if (!_initialized) {
initialize();
} else {
}
return _execStream;
}
void* ContextBuffers::specialStream() {
if (!_initialized) {
initialize();
} else {
}
return _specialStream;
}
bool ContextBuffers::isInitialized() { return _initialized; }
ErrorReference* ContextBuffers::errorReference() { return &_errorReference; }
} // namespace sd
@@ -0,0 +1,473 @@
#include "DeviceValidator.h"
ValidationResult::ValidationResult()
: isComputeCapabilitySufficient(true),
isManagedMemorySupported(true),
isComputePreemptionSupported(true),
isThreadsPerBlockWithinLimit(true),
isBlocksWithinGridSizeLimit(true),
isSharedMemoryUsageWithinLimit(true),
isRegisterUsageWithinLimit(true),
isTotalThreadsWithinLimit(true),
isGlobalMemoryUsageWithinLimit(true),
isMemoryUsageWithinLimit(true),
isLocalMemoryUsageWithinLimit(true),
isConcurrentKernelsSupported(true),
isL2CacheSizeSufficient(true) {}
DeviceValidator* DeviceValidator::instance = nullptr;
std::mutex DeviceValidator::mtx;
DeviceValidator* DeviceValidator::getInstance(const std::string& directory, int device) {
std::lock_guard<std::mutex> lock(mtx);
if (instance == nullptr) {
instance = new DeviceValidator(directory, device);
}
return instance;
}
DeviceValidator::DeviceValidator(const std::string& directoryPath, int device)
: directoryPath(directoryPath) {
cudaGetDeviceProperties(&prop, device);
init();
}
DeviceValidator::~DeviceValidator() {
for (auto& pair : moduleMap) {
cuModuleUnload(pair.second);
}
moduleMap.clear();
functionMap.clear();
}
std::vector<std::string> DeviceValidator::parsePTXFile(const std::string& filePath) {
std::ifstream file(filePath);
std::string line;
std::vector<std::string> functionNames;
std::regex functionPattern("\\.entry\\s+([a-zA-Z_][a-zA-Z0-9_]*)");
while (std::getline(file, line)) {
std::smatch match;
if (std::regex_search(line, match, functionPattern) && match.size() > 1) {
functionNames.push_back(match.str(1));
}
}
return functionNames;
}
std::vector<std::string> DeviceValidator::parseCUBINFile(const std::string& filePath) {
std::string command = "cuobjdump -sass " + filePath + " | grep -oP '(?<=FUNC ).*(?=\\()'";
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.c_str(), "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
std::stringstream ss(result);
std::string functionName;
std::vector<std::string> functionNames;
while (std::getline(ss, functionName, '\n')) {
functionNames.push_back(functionName);
}
return functionNames;
}
void DeviceValidator::init() {
// Check if cuobjdump is available
#ifdef _WIN32
// Windows
if (system("cuobjdump --version > nul 2>&1") != 0) {
throw std::runtime_error("cuobjdump is not available on the system's PATH. Please install it and try again.");
}
#else
// Linux
if (system("cuobjdump --version > /dev/null 2>&1") != 0) {
throw std::runtime_error("cuobjdump is not available on the system's PATH. Please install it and try again.");
}
#endif
printf("Initializing DeviceValidator at path %s\n", directoryPath.c_str());
for (const auto &entry : std::filesystem::directory_iterator(directoryPath)) {
if (entry.path().extension() == ".ptx" || entry.path().extension() == ".cubin") {
CUmodule cuModule;
printf("Adding path %s\n",entry.path().filename().c_str());
if (cuModuleLoad(&cuModule, entry.path().c_str()) == CUDA_SUCCESS) {
moduleMap[entry.path().filename().string()] = cuModule;
if (entry.path().extension() == ".ptx") {
std::vector<std::string> functionNames = parsePTXFile(entry.path().c_str());
for (const auto& functionName : functionNames) {
CUfunction cuFunction;
if (cuModuleGetFunction(&cuFunction, cuModule, functionName.c_str()) == CUDA_SUCCESS) {
functionMap[functionName] = cuFunction;
}
}
} else if (entry.path().extension() == ".cubin") {
std::vector<std::string> functionNames = parseCUBINFile(entry.path().c_str());
for (const auto& functionName : functionNames) {
CUfunction cuFunction;
if (cuModuleGetFunction(&cuFunction, cuModule, functionName.c_str()) == CUDA_SUCCESS) {
functionMap[functionName] = cuFunction;
}
}
}
}
}
}
}
void DeviceValidator::setKernelAttribute(const std::string& functionName, CUfunction_attribute attribute, int value) {
if (functionMap.find(functionName) != functionMap.end()) {
cuFuncSetAttribute(functionMap[functionName], attribute, value);
}
}
void DeviceValidator::setKernelMaxDynamicSharedSizeBytes(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, value);
}
void DeviceValidator::setKernelPreferredSharedMemoryCarveout(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT, value);
}
void DeviceValidator::setKernelMaxRegisters(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_NUM_REGS, value);
}
void DeviceValidator::setKernelMaxThreadsPerBlock(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, value);
}
void DeviceValidator::setKernelNumRegs(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_NUM_REGS, value);
}
void DeviceValidator::setKernelSharedSizeBytes(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, value);
}
void DeviceValidator::setKernelBinaryVersion(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_BINARY_VERSION, value);
}
void DeviceValidator::setKernelCacheModeCA(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_CACHE_MODE_CA, value);
}
void DeviceValidator::setKernelMaxThreadsPerBlockOptIn(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, value);
}
void DeviceValidator::setKernelReservedSharedSizeBytes(const std::string& functionName, int value) {
setKernelAttribute(functionName, CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, value);
}
void DeviceValidator::setAllKernelsAttribute(CUfunction_attribute attribute, int value) {
for (auto& pair : functionMap) {
cuFuncSetAttribute(pair.second, attribute, value);
}
}
void DeviceValidator::setAllKernelsMaxDynamicSharedSizeBytes(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, value);
}
void DeviceValidator::setAllKernelsPreferredSharedMemoryCarveout(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT, value);
}
void DeviceValidator::setAllKernelsMaxRegisters(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_NUM_REGS, value);
}
void DeviceValidator::setAllKernelsMaxThreadsPerBlock(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, value);
}
void DeviceValidator::setAllKernelsNumRegs(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_NUM_REGS, value);
}
void DeviceValidator::setAllKernelsSharedSizeBytes(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, value);
}
void DeviceValidator::setAllKernelsBinaryVersion(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_BINARY_VERSION, value);
}
void DeviceValidator::setAllKernelsCacheModeCA(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_CACHE_MODE_CA, value);
}
void DeviceValidator::setAllKernelsMaxThreadsPerBlockOptIn(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, value);
}
void DeviceValidator::setAllKernelsReservedSharedSizeBytes(int value) {
setAllKernelsAttribute(CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, value);
}
void DeviceValidator::printKernelAttribute(const char* name, CUfunction_attribute attribute) {
CUfunction kernel = functionMap[name];
int value;
cuFuncGetAttribute(&value, attribute, kernel);
std::cout << "Attribute " << attribute << " for function " << name << " is " << value << std::endl;
}
ValidationResult DeviceValidator::validateKernelLaunch(const char* name, dim3 threadsPerBlock, dim3 numBlocks,
size_t globalMemoryUsage) {
ValidationResult result;
CUfunction kernel;
// Look up the function from the function map
auto it = functionMap.find(name);
if (it != functionMap.end()) {
kernel = it->second;
} else {
// If the function is not found in the map, return an invalid ValidationResult
return result;
}
int sharedSizeBytes, numRegs, maxThreadsPerBlock;
cuFuncGetAttribute(&sharedSizeBytes, CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, kernel);
cuFuncGetAttribute(&numRegs, CU_FUNC_ATTRIBUTE_NUM_REGS, kernel);
cuFuncGetAttribute(&maxThreadsPerBlock, CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, kernel);
result.sharedSizeBytes = sharedSizeBytes;
result.numRegs = numRegs;
result.maxThreadsPerBlock = maxThreadsPerBlock;
result.isComputeCapabilitySufficient = true;
result.isECCMemorySupported = prop.ECCEnabled;
result.isManagedMemorySupported = prop.managedMemory;
result.isComputePreemptionSupported = prop.computePreemptionSupported;
result.isConcurrentKernelsSupported = prop.concurrentKernels;
result.isL2CacheSizeSufficient = prop.l2CacheSize;
result.isThreadsPerBlockWithinLimit = threadsPerBlock.x * threadsPerBlock.y * threadsPerBlock.z <= prop.maxThreadsPerBlock;
result.isThreadsPerBlockWithinLimit &= threadsPerBlock.x * threadsPerBlock.y * threadsPerBlock.z <= maxThreadsPerBlock;
result.numBlocks = numBlocks.x;
result.isBlocksWithinGridSizeLimit = numBlocks.x <= prop.maxGridSize[0] && numBlocks.y <= prop.maxGridSize[1] && numBlocks.z <= prop.maxGridSize[2];
result.isSharedMemoryUsageWithinLimit = sharedSizeBytes <= prop.sharedMemPerBlock;
result.isRegisterUsageWithinLimit = numRegs * threadsPerBlock.x * threadsPerBlock.y * threadsPerBlock.z <= prop.regsPerBlock;
result.numThreads = threadsPerBlock.x * threadsPerBlock.y * threadsPerBlock.z * numBlocks.x * numBlocks.y * numBlocks.z;
result.isTotalThreadsWithinLimit = threadsPerBlock.x * threadsPerBlock.y * threadsPerBlock.z * numBlocks.x * numBlocks.y * numBlocks.z <= prop.maxThreadsPerMultiProcessor * prop.multiProcessorCount;
result.isGlobalMemoryUsageWithinLimit = globalMemoryUsage <= prop.totalGlobalMem;
result.globalMemory = globalMemoryUsage;
size_t freeMemory, totalMemory;
cudaMemGetInfo(&freeMemory, &totalMemory);
size_t usedMemory = totalMemory - freeMemory;
result.memoryUsage = usedMemory + globalMemoryUsage;
result.isMemoryUsageWithinLimit = result.memoryUsage <= totalMemory;
result.isLocalMemoryUsageWithinLimit = usedMemory + globalMemoryUsage <= prop.localL1CacheSupported ? totalMemory : prop.localL1CacheSupported;
result.freeMemory = freeMemory;
result.totalMemory = totalMemory;
return result;
}
void DeviceValidator::printProblematicFunctions(dim3 threadsPerBlock, dim3 numBlocks, size_t globalMemory) {
printf("Attempting to print functions with size of map %d\n",functionMap.size());
for (const auto& pair : functionMap) {
const std::string functionName = pair.first;
CUfunction function = pair.second;
ValidationResult validationResult = validateKernelLaunch(functionName.c_str(),threadsPerBlock, numBlocks, globalMemory);
if (!validationResult.isValid()) {
std::cout << "Function " << functionName << " has the following problems:\n";
printValidationResult(functionName.c_str(),validationResult);
std::cout << std::endl;
}
}
}
bool ValidationResult::isValid() {
return isComputeCapabilitySufficient &&
isManagedMemorySupported &&
isComputePreemptionSupported &&
isThreadsPerBlockWithinLimit &&
isBlocksWithinGridSizeLimit &&
isSharedMemoryUsageWithinLimit &&
isRegisterUsageWithinLimit &&
isTotalThreadsWithinLimit &&
isGlobalMemoryUsageWithinLimit &&
isMemoryUsageWithinLimit &&
isLocalMemoryUsageWithinLimit &&
isConcurrentKernelsSupported &&
isL2CacheSizeSufficient;
}
void DeviceValidator::printValidationResult(const char* name, ValidationResult& result) {
printf("Validating: %s\n",name);
if (!result.isValid()) {
std::cout << "Function " << name << " has an issue:\n";
if (!result.isComputeCapabilitySufficient) {
std::cout << " - Compute capability is not sufficient. Required: " << result.isComputeCapabilitySufficient << ", Actual: " << prop.major * 10 + prop.minor << "\n";
}
if (!result.isManagedMemorySupported) {
std::cout << " - Managed memory is not supported.\n";
}
if (!result.isComputePreemptionSupported) {
std::cout << " - Compute preemption is not supported.\n";
}
if (!result.isThreadsPerBlockWithinLimit) {
std::cout << " - Threads per block is not within limit. Max: " << prop.maxThreadsPerBlock << "\n";
std::cout << " - Value is: " << result.maxThreadsPerBlock << "\n";
}
if (!result.isBlocksWithinGridSizeLimit) {
// result.isRegisterUsageWithinLimit = numRegs * threadsPerBlock.x * threadsPerBlock.y * threadsPerBlock.z <= prop.regsPerBlock;
std::cout << " - Blocks within grid size is not within limit. Max: (" << prop.maxGridSize[0] << ", " << prop.maxGridSize[1] << ", " << prop.maxGridSize[2] << ")\n";
std::cout << " - Value is: (" << result.numBlocks << ", " << result.numBlocks << ", " << result.numBlocks << ")\n";
}
if (!result.isSharedMemoryUsageWithinLimit) {
std::cout << " - Shared memory usage is not within limit. Max: " << prop.sharedMemPerBlock << "\n";
}
if (!result.isRegisterUsageWithinLimit) {
std::cout << " - Register usage is not within limit. Max: " << prop.regsPerBlock << "\n";
std::cout << " - Value is: (" << result.numRegs << ", " << result.numBlocks << "\n";
}
if (!result.isTotalThreadsWithinLimit) {
std::cout << " - Total threads is not within limit. Max: " << prop.maxThreadsPerMultiProcessor * prop.multiProcessorCount << "\n";
std::cout << " - Value is: " << result.numThreads << "\n";
}
if (!result.isGlobalMemoryUsageWithinLimit) {
std::cout << " - Global memory usage is not within limit. Max: " << prop.totalGlobalMem << "\n";
std::cout << " - Value is: " << result.globalMemory << "\n";
}
if (!result.isMemoryUsageWithinLimit) {
std::cout << " - Memory usage is not within limit.\n";
std::cout << " - Value is: " << result.memoryUsage << "\n";
}
if (!result.isLocalMemoryUsageWithinLimit) {
std::cout << " - Local memory usage is not within limit. Max: " << (prop.localL1CacheSupported ? prop.localL1CacheSupported : prop.totalGlobalMem) << "\n";
}
if (!result.isConcurrentKernelsSupported) {
std::cout << " - Concurrent kernels is not supported.\n";
}
if (!result.isL2CacheSizeSufficient) {
std::cout << " - L2 cache size is not sufficient. Max: " << prop.l2CacheSize << "\n";
}
}
}
void DeviceValidator::printMaxKernelAttributes() {
std::cout << "Device name: " << prop.name << std::endl;
std::cout << "Total global memory: " << prop.totalGlobalMem << std::endl;
std::cout << "Shared memory per block: " << prop.sharedMemPerBlock << std::endl;
std::cout << "Registers per block: " << prop.regsPerBlock << std::endl;
std::cout << "Warp size: " << prop.warpSize << std::endl;
std::cout << "Max pitch: " << prop.memPitch << std::endl;
std::cout << "Max threads per block: " << prop.maxThreadsPerBlock << std::endl;
std::cout << "Max thread dimensions: (" << prop.maxThreadsDim[0] << ", " << prop.maxThreadsDim[1] << ", " << prop.maxThreadsDim[2] << ")" << std::endl;
std::cout << "Max grid dimensions: (" << prop.maxGridSize[0] << ", " << prop.maxGridSize[1] << ", " << prop.maxGridSize[2] << ")" << std::endl;
std::cout << "Clock rate: " << prop.clockRate << std::endl;
std::cout << "Total constant memory: " << prop.totalConstMem << std::endl;
std::cout << "Compute capability: " << prop.major << "." << prop.minor << std::endl;
std::cout << "Texture alignment: " << prop.textureAlignment << std::endl;
std::cout << "Concurrent copy and execution: " << (prop.deviceOverlap ? "Yes" : "No") << std::endl;
std::cout << "Number of multiprocessors: " << prop.multiProcessorCount << std::endl;
std::cout << "Kernel execution timeout: " << (prop.kernelExecTimeoutEnabled ? "Yes" : "No") << std::endl;
std::cout << "Integrated: " << (prop.integrated ? "Yes" : "No") << std::endl;
std::cout << "Can map host memory: " << (prop.canMapHostMemory ? "Yes" : "No") << std::endl;
std::cout << "Compute mode: " << (prop.computeMode == cudaComputeModeDefault ? "Default" : (prop.computeMode == cudaComputeModeExclusive ? "Exclusive" : (prop.computeMode == cudaComputeModeProhibited ? "Prohibited" : "Exclusive Process"))) << std::endl;
std::cout << "Max texture 1D: " << prop.maxTexture1D << std::endl;
std::cout << "Max texture 2D: (" << prop.maxTexture2D[0] << ", " << prop.maxTexture2D[1] << ")" << std::endl;
std::cout << "Max texture 3D: (" << prop.maxTexture3D[0] << ", " << prop.maxTexture3D[1] << ", " << prop.maxTexture3D[2] << ")" << std::endl;
std::cout << "Concurrent kernels: " << (prop.concurrentKernels ? "Yes" : "No") << std::endl;
std::cout << "ECC enabled: " << (prop.ECCEnabled ? "Yes" : "No") << std::endl;
std::cout << "PCI bus ID: " << prop.pciBusID << std::endl;
std::cout << "PCI device ID: " << prop.pciDeviceID << std::endl;
std::cout << "TCC driver: " << (prop.tccDriver ? "Yes" : "No") << std::endl;
std::cout << "Memory clock rate: " << prop.memoryClockRate << std::endl;
std::cout << "Global memory bus width: " << prop.memoryBusWidth << std::endl;
std::cout << "L2 cache size: " << prop.l2CacheSize << std::endl;
std::cout << "Max threads per multiprocessor: " << prop.maxThreadsPerMultiProcessor << std::endl;
std::cout << "Stream priorities supported: " << (prop.streamPrioritiesSupported ? "Yes" : "No") << std::endl;
std::cout << "Global L1 cache supported: " << (prop.globalL1CacheSupported ? "Yes" : "No") << std::endl;
std::cout << "Local L1 cache supported: " << (prop.localL1CacheSupported ? "Yes" : "No") << std::endl;
std::cout << "Shared memory per multiprocessor: " << prop.sharedMemPerMultiprocessor << std::endl;
std::cout << "Registers per multiprocessor: " << prop.regsPerMultiprocessor << std::endl;
std::cout << "Managed memory concurrent: " << (prop.concurrentManagedAccess ? "Yes" : "No") << std::endl;
std::cout << "Is multi GPU board: " << (prop.isMultiGpuBoard ? "Yes" : "No") << std::endl;
std::cout << "Multi GPU board group ID: " << prop.multiGpuBoardGroupID << std::endl;
std::cout << "Host native atomic supported: " << (prop.hostNativeAtomicSupported ? "Yes" : "No") << std::endl;
std::cout << "Single to double precision perf ratio: " << prop.singleToDoublePrecisionPerfRatio << std::endl;
std::cout << "Pageable memory access: " << (prop.pageableMemoryAccess ? "Yes" : "No") << std::endl;
std::cout << "Concurrent managed access: " << (prop.concurrentManagedAccess ? "Yes" : "No") << std::endl;
}
void DeviceValidator::printKernelAttributes(const char* name) {
auto it = functionMap.find(name);
if (it == functionMap.end()) {
std::cerr << "Error: Function " << name << " not found." << std::endl;
return;
}
CUfunction kernel = it->second;
int sharedSizeBytes, numRegs, maxThreadsPerBlock, binaryVersion, cacheModeCA, maxDynamicSharedSizeBytes, preferredSharedMemoryCarveout;
cuFuncGetAttribute(&sharedSizeBytes, CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, kernel);
cuFuncGetAttribute(&numRegs, CU_FUNC_ATTRIBUTE_NUM_REGS, kernel);
cuFuncGetAttribute(&maxThreadsPerBlock, CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, kernel);
cuFuncGetAttribute(&binaryVersion, CU_FUNC_ATTRIBUTE_BINARY_VERSION, kernel);
cuFuncGetAttribute(&cacheModeCA, CU_FUNC_ATTRIBUTE_CACHE_MODE_CA, kernel);
cuFuncGetAttribute(&maxDynamicSharedSizeBytes, CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, kernel);
cuFuncGetAttribute(&preferredSharedMemoryCarveout, CU_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT, kernel);
std::cout << "Kernel name: " << name << std::endl;
std::cout << "Shared memory per block: " << sharedSizeBytes << std::endl;
std::cout << "Registers per block: " << numRegs << std::endl;
std::cout << "Max threads per block: " << maxThreadsPerBlock << std::endl;
std::cout << "Binary version: " << binaryVersion << std::endl;
std::cout << "Cache mode CA: " << cacheModeCA << std::endl;
std::cout << "Max dynamic shared size bytes: " << maxDynamicSharedSizeBytes << std::endl;
std::cout << "Preferred shared memory carveout: " << preferredSharedMemoryCarveout << std::endl;
if (sharedSizeBytes > prop.sharedMemPerBlock) {
std::cout << "WARNING: The kernel uses more shared memory per block than the device supports." << std::endl;
}
if (numRegs > prop.regsPerBlock) {
std::cout << "WARNING: The kernel uses more registers per block than the device supports." << std::endl;
}
if (maxThreadsPerBlock > prop.maxThreadsPerBlock) {
std::cout << "WARNING: The kernel uses more threads per block than the device supports." << std::endl;
}
// Note: There are no device properties to compare with binaryVersion, cacheModeCA, maxDynamicSharedSizeBytes, and preferredSharedMemoryCarveout.
}
std::map<std::string, ValidationResult> DeviceValidator::collectResourceProblems() {
std::map<std::string, ValidationResult> problematicFunctions;
for (const auto& pair : functionMap) {
const char* name = pair.first.c_str();
ValidationResult result = validateKernelLaunch(name, dim3(1, 1, 1), dim3(1, 1, 1), 0);
if (!result.isComputeCapabilitySufficient ||
!result.isECCMemorySupported ||
!result.isManagedMemorySupported ||
!result.isComputePreemptionSupported ||
!result.isThreadsPerBlockWithinLimit ||
!result.isBlocksWithinGridSizeLimit ||
!result.isSharedMemoryUsageWithinLimit ||
!result.isRegisterUsageWithinLimit ||
!result.isTotalThreadsWithinLimit ||
!result.isGlobalMemoryUsageWithinLimit ||
!result.isMemoryUsageWithinLimit ||
!result.isLocalMemoryUsageWithinLimit ||
!result.isConcurrentKernelsSupported ||
!result.isL2CacheSizeSufficient) {
problematicFunctions[name] = result;
}
}
return problematicFunctions;
}
@@ -0,0 +1,107 @@
#include <cuda.h>
#include <algorithm>
#include <filesystem>
#include <iostream>
#include <map>
#include <mutex>
#include <unordered_map>
#include <fstream>
#include <regex>
#include <string>
#include <vector>
class ValidationResult {
public:
bool isComputeCapabilitySufficient;
bool isECCMemorySupported;
bool isManagedMemorySupported;
bool isComputePreemptionSupported;
bool isThreadsPerBlockWithinLimit;
bool isBlocksWithinGridSizeLimit;
bool isSharedMemoryUsageWithinLimit;
bool isRegisterUsageWithinLimit;
bool isTotalThreadsWithinLimit;
bool isGlobalMemoryUsageWithinLimit;
bool isMemoryUsageWithinLimit;
bool isLocalMemoryUsageWithinLimit;
bool isConcurrentKernelsSupported;
bool isL2CacheSizeSufficient;
int sharedSizeBytes, numRegs, maxThreadsPerBlock;
size_t freeMemory, totalMemory;
int numBlocks;
int globalMemory;
int numThreads;
int memoryUsage;
bool isValid();
ValidationResult();
};
class DeviceValidator {
private:
cudaDeviceProp prop;
static std::mutex mtx;
std::unordered_map<std::string, CUmodule> moduleMap;
std::unordered_map<std::string, CUfunction> functionMap;
std::string directoryPath;
static DeviceValidator* instance;
void init();
public:
DeviceValidator(const std::string& directoryPath, int device = 0);
~DeviceValidator();
static DeviceValidator* getInstance(const std::string& directory, int device = 0);
// Set kernel attribute
void setKernelAttribute(const std::string& functionName, CUfunction_attribute attribute, int value);
void setKernelMaxDynamicSharedSizeBytes(const std::string& functionName, int value);
void setKernelPreferredSharedMemoryCarveout(const std::string& functionName, int value);
void setKernelMaxRegisters(const std::string& functionName, int value);
void setKernelMaxThreadsPerBlock(const std::string& functionName, int value);
void setKernelNumRegs(const std::string& functionName, int value);
void setKernelSharedSizeBytes(const std::string& functionName, int value);
void setKernelBinaryVersion(const std::string& functionName, int value);
void setKernelCacheModeCA(const std::string& functionName, int value);
void setKernelMaxThreadsPerBlockOptIn(const std::string& functionName, int value);
void setKernelReservedSharedSizeBytes(const std::string& functionName, int value);
void setAllKernelsAttribute(CUfunction_attribute attribute, int value);
void setAllKernelsMaxDynamicSharedSizeBytes(int value);
void setAllKernelsPreferredSharedMemoryCarveout(int value);
void setAllKernelsMaxRegisters(int value);
void setAllKernelsMaxThreadsPerBlock(int value);
void setAllKernelsNumRegs(int value);
void setAllKernelsSharedSizeBytes(int value);
void setAllKernelsBinaryVersion(int value);
void setAllKernelsCacheModeCA(int value);
void setAllKernelsMaxThreadsPerBlockOptIn(int value);
void setAllKernelsReservedSharedSizeBytes(int value);
void printKernelAttribute(const char* name, CUfunction_attribute attribute);
void printMaxKernelAttributes();
void printKernelAttributes(const char* name);
std::map<std::string, ValidationResult> collectResourceProblems();
void printValidationResult(const char* name, ValidationResult& result);
ValidationResult validateKernelLaunch(const char* name, dim3 threadsPerBlock, dim3 numBlocks,
size_t globalMemoryUsage);
void printProblematicFunctions(dim3 threadsPerBlock, dim3 numBlocks, size_t globalMemory);
std::vector<std::string> parseCUBINFile(const std::string& filePath);
std::vector<std::string> parsePTXFile(const std::string& filePath);
};
@@ -0,0 +1,160 @@
/* ******************************************************************************
*
*
* 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.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* 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
******************************************************************************/
//
// @author raver119@gmail.com
//
#include <exceptions/cuda_exception.h>
#include <execution/AffinityManager.h>
#include <execution/LaunchContext.h>
#include <helpers/cublasHelper.h>
#include <helpers/logger.h>
#include <thread>
thread_local sd::ContextBuffers contextBuffers = sd::ContextBuffers();
namespace sd {
// This avoids static destruction order crashes during JVM shutdown
std::vector<LaunchContext*>& LaunchContext::contexts() {
static std::vector<LaunchContext*>* _contexts = new std::vector<LaunchContext*>();
return *_contexts;
}
std::mutex LaunchContext::_mutex;
SD_MAP_IMPL<int, std::mutex*> LaunchContext::_deviceMutexes;
////////////////////////////////////////////////////////////////////////
LaunchContext::LaunchContext(cudaStream_t* cudaStream, cudaStream_t& specialCudaStream, void* reductionPointer,
void* scalarPointer, int* allocationPointer) {
_workspace = nullptr;
_isAllocated = false;
}
std::mutex* LaunchContext::deviceMutex() {
auto deviceId = AffinityManager::currentDeviceId();
return _deviceMutexes[deviceId];
}
LaunchContext::~LaunchContext() {
if (_isAllocated) {
}
}
////////////////////////////////////////////////////////////////////////
LaunchContext::LaunchContext() {
// default constructor, just to make clang/ranlib happy
_workspace = nullptr;
_deviceID = 0;
_isAllocated = true;
}
LaunchContext::LaunchContext(Pointer cudaStream, Pointer reductionPointer, Pointer scalarPointer,
Pointer allocationPointer) {
_isAllocated = false;
}
LaunchContext* LaunchContext::defaultContext() {
/**
* This method returns LaunchContext, that has multiple entities within:
* 1) temporary buffers. they must be per-thread
* 2) CUDA stream. it must be either per-thread or per-device
* 3) cuBLAS handle. it must be per-device
*/
auto deviceId = AffinityManager::currentDeviceId();
{
// we need this block synchronous, to avoid double initialization etc
std::lock_guard<std::mutex> lock(_mutex);
if (contexts().empty()) {
// create one context per device
auto numDevices = AffinityManager::numberOfDevices();
contexts().resize(numDevices);
for (int e = 0; e < numDevices; e++) {
_deviceMutexes[e] = new std::mutex();
AffinityManager::setCurrentNativeDevice(e);
contexts().at(e) = new LaunchContext();
}
// don't forget to restore device back again
AffinityManager::setCurrentNativeDevice(deviceId);
}
}
// return context for current device
return contexts().at(deviceId);
}
void* LaunchContext::getReductionPointer() const { return contextBuffers.reductionBuffer(); };
void* LaunchContext::getScalarPointer() const { return contextBuffers.scalarBuffer(); };
LongType* LaunchContext::getAllocationPointer() const { return reinterpret_cast<LongType*>(contextBuffers.allocationBuffer()); };
void* LaunchContext::getCublasHandle() const { return CublasHelper::getInstance().handle(); };
void* LaunchContext::getCusolverHandle() const { return CublasHelper::getInstance().solver(); };
cudaStream_t* LaunchContext::getCudaStream() const {
return reinterpret_cast<cudaStream_t*>(contextBuffers.execStream());
};
cudaStream_t* LaunchContext::getCudaSpecialStream() const {
return reinterpret_cast<cudaStream_t*>(contextBuffers.specialStream());
;
};
void LaunchContext::setReductionPointer(void* reductionPointer) {
contextBuffers.setReductionBuffer(reductionPointer);
};
void LaunchContext::setScalarPointer(void* scalarPointer) { contextBuffers.setScalarBuffer(scalarPointer); };
void LaunchContext::setAllocationPointer(int* allocationPointer) {
contextBuffers.setAllocationBuffer(allocationPointer);
};
void LaunchContext::setCudaStream(cudaStream_t* cudaStream){
};
void LaunchContext::setCudaSpecialStream(cudaStream_t* cudaStream){
};
void LaunchContext::setCublasHandle(void* handle) { _cublasHandle = handle; };
void LaunchContext::swapContextBuffers(ContextBuffers& buffers) { contextBuffers = buffers; };
void LaunchContext::releaseBuffers() {
contextBuffers.release();
}
bool LaunchContext::isInitialized() { return contextBuffers.isInitialized(); }
void* LaunchContext::getCuDnnHandle() const { return CublasHelper::getInstance().cudnn(); }
ErrorReference* LaunchContext::errorReference() { return contextBuffers.errorReference(); }
void* LaunchContext::engine() { return _engine; }
} // namespace sd
File diff suppressed because it is too large Load Diff
+867
View File
@@ -0,0 +1,867 @@
#if !defined(LAUNCH_DIMS_H)
#pragma once
#include <cstdlib>
#include <unordered_map>
#include <string>
#include <cuda_runtime.h>
#include <map>
#include <helpers/CudaLaunchHelper.h>
#include <array/NDArray.h>
// Retrieve the environment variable value for the given variable name
int getEnvVariable(const std::string& varName, int defaultValue);
// Grid, block, and shared memory size definitions using environment variables
#define GRID_SIZE_ADJUST_WEIGHTS getEnvVariable("GRID_SIZE_ADJUST_WEIGHTS", 256)
#define BLOCK_SIZE_ADJUST_WEIGHTS getEnvVariable("BLOCK_SIZE_ADJUST_WEIGHTS", 512)
#define SHARED_MEM_SIZE_ADJUST_WEIGHTS getEnvVariable("SHARED_MEM_SIZE_ADJUST_WEIGHTS", 8192)
//note we only use the shared memory for this op the rest are array specific
#define GRID_SIZE_SEQUENCE_MASK getEnvVariable("GRID_SIZE_SEQUENCE_MASK", 256)
#define BLOCK_SIZE_SEQUENCE_MASK getEnvVariable("BLOCK_SIZE_SEQUENCE_MASK", 256)
#define SHARED_MEM_SIZE_SEQUENCE_MASK getEnvVariable("SHARED_MEM_SIZE_SEQUENCE_MASK", 128)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_SEGMENT_SUM getEnvVariable("GRID_SIZE_SEGMENT_SUM", 256)
#define BLOCK_SIZE_SEGMENT_SUM getEnvVariable("BLOCK_SIZE_SEGMENT_SUM", 256)
#define SHARED_MEM_SIZE_SEGMENT_SUM getEnvVariable("SHARED_MEM_SIZE_SEGMENT_SUM", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_UNSORTED_SEGMENT_SUM getEnvVariable("GRID_SIZE_UNSORTED_SEGMENT_SUM", 256)
#define BLOCK_SIZE_UNSORTED_SEGMENT_SUM getEnvVariable("BLOCK_SIZE_UNSORTED_SEGMENT_SUM", 256)
#define SHARED_MEM_SIZE_UNSORTED_SEGMENT_SUM getEnvVariable("SHARED_MEM_SIZE_UNSORTED_SEGMENT_SUM", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_SEGMENT_SQRTN getEnvVariable("GRID_SIZE_SEGMENT_SQRTN", 128)
#define BLOCK_SIZE_SEGMENT_SQRTN getEnvVariable("BLOCK_SIZE_SEGMENT_SQRTN", 256)
#define SHARED_MEM_SIZE_SEGMENT_SQRTN getEnvVariable("SHARED_MEM_SIZE_SEGMENT_SQRTN", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_SEGMENT_PROD getEnvVariable("GRID_SIZE_SEGMENT_PROD", 256)
#define BLOCK_SIZE_SEGMENT_PROD getEnvVariable("BLOCK_SIZE_SEGMENT_PROD", 256)
#define SHARED_MEM_SIZE_SEGMENT_PROD getEnvVariable("SHARED_MEM_SIZE_SEGMENT_PROD", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_UNSORTED_SEGMENT_PROD getEnvVariable("GRID_SIZE_UNSORTED_SEGMENT_PROD", 256)
#define BLOCK_SIZE_UNSORTED_SEGMENT_PROD getEnvVariable("BLOCK_SIZE_UNSORTED_SEGMENT_PROD", 256)
#define SHARED_MEM_SIZE_UNSORTED_SEGMENT_PROD getEnvVariable("SHARED_MEM_SIZE_UNSORTED_SEGMENT_PROD", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_SEGMENT_MIN getEnvVariable("GRID_SIZE_SEGMENT_MIN", 256)
#define BLOCK_SIZE_SEGMENT_MIN getEnvVariable("BLOCK_SIZE_SEGMENT_MIN", 256)
#define SHARED_MEM_SIZE_SEGMENT_MIN getEnvVariable("SHARED_MEM_SIZE_SEGMENT_MIN", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_UNSORTED_SEGMENT_MIN getEnvVariable("GRID_SIZE_UNSORTED_SEGMENT_MIN", 256)
#define BLOCK_SIZE_UNSORTED_SEGMENT_MIN getEnvVariable("BLOCK_SIZE_UNSORTED_SEGMENT_MIN", 256)
#define SHARED_MEM_SIZE_UNSORTED_SEGMENT_MIN getEnvVariable("SHARED_MEM_SIZE_UNSORTED_SEGMENT_MIN", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_SEGMENT_MEAN getEnvVariable("GRID_SIZE_SEGMENT_MEAN", 256)
#define BLOCK_SIZE_SEGMENT_MEAN getEnvVariable("BLOCK_SIZE_SEGMENT_MEAN", 256)
#define SHARED_MEM_SIZE_SEGMENT_MEAN getEnvVariable("SHARED_MEM_SIZE_SEGMENT_MEAN", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_UNSORTED_SEGMENT_MEAN getEnvVariable("GRID_SIZE_UNSORTED_SEGMENT_MEAN", 256)
#define BLOCK_SIZE_UNSORTED_SEGMENT_MEAN getEnvVariable("BLOCK_SIZE_UNSORTED_SEGMENT_MEAN", 256)
#define SHARED_MEM_SIZE_UNSORTED_SEGMENT_MEAN getEnvVariable("SHARED_MEM_SIZE_UNSORTED_SEGMENT_MEAN", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_SEGMENT_MAX getEnvVariable("GRID_SIZE_SEGMENT_MAX", 256)
#define BLOCK_SIZE_SEGMENT_MAX getEnvVariable("BLOCK_SIZE_SEGMENT_MAX", 512)
#define SHARED_MEM_SIZE_SEGMENT_MAX getEnvVariable("SHARED_MEM_SIZE_SEGMENT_MAX", 256)
//not we don't really use this due to defaults being array specific for this op
#define GRID_SIZE_UNSORTED_SEGMENT_MAX getEnvVariable("GRID_SIZE_UNSORTED_SEGMENT_MAX", 256)
#define BLOCK_SIZE_UNSORTED_SEGMENT_MAX getEnvVariable("BLOCK_SIZE_UNSORTED_SEGMENT_MAX", 256)
#define SHARED_MEM_SIZE_UNSORTED_SEGMENT_MAX getEnvVariable("SHARED_MEM_SIZE_UNSORTED_SEGMENT_MAX", 256)
#define GRID_SIZE_MATRIX_DIAG getEnvVariable("GRID_SIZE_MATRIX_DIAG", 256)
#define BLOCK_SIZE_MATRIX_DIAG getEnvVariable("BLOCK_SIZE_MATRIX_DIAG", 512)
#define SHARED_MEM_SIZE_MATRIX_DIAG getEnvVariable("SHARED_MEM_SIZE_MATRIX_DIAG", 8192)
//not we don't really use this due to defaults being array specific for this op (see fillUpSegments_)
#define GRID_SIZE_SEGMENT_FILL_UP_SEGMENTS getEnvVariable("GRID_SIZE_SEGMENT_FILL_UP_SEGMENTS", 256)
#define BLOCK_SIZE_SEGMENT_FILL_UP_SEGMENTS getEnvVariable("BLOCK_SIZE_SEGMENT_FILL_UP_SEGMENTS", 256)
#define SHARED_MEM_SIZE_SEGMENT_FILL_UP_SEGMENTS getEnvVariable("SHARED_MEM_SIZE_SEGMENT_FILL_UP_SEGMENTS", 256)
#define GRID_SIZE_MATRIX_BAND getEnvVariable("GRID_SIZE_MATRIX_BAND", 256)
#define BLOCK_SIZE_MATRIX_BAND getEnvVariable("BLOCK_SIZE_MATRIX_BAND", 512)
#define SHARED_MEM_SIZE_MATRIX_BAND getEnvVariable("SHARED_MEM_SIZE_MATRIX_BAND", 8192)
#define GRID_SIZE_LUP getEnvVariable("GRID_SIZE_LUP", 256)
#define BLOCK_SIZE_LUP getEnvVariable("BLOCK_SIZE_LUP", 256)
#define SHARED_MEM_SIZE_LUP getEnvVariable("SHARED_MEM_SIZE_LUP", 256)
#define GRID_SIZE_ISMAX getEnvVariable("GRID_SIZE_ISMAX", 256)
#define BLOCK_SIZE_ISMAX getEnvVariable("BLOCK_SIZE_ISMAX", 256)
#define SHARED_MEM_SIZE_ISMAX getEnvVariable("SHARED_MEM_SIZE_ISMAX", 16384)
#define GRID_SIZE_ISMAX_FILL getEnvVariable("GRID_SIZE_ISMAXGRID_SIZE_ISMAX_FILL", 128)
#define BLOCK_SIZE_ISMAX_FILL getEnvVariable("BLOCK_SIZE_ISMAXBLOCK_SIZE_ISMAX_FILL", 512)
#define SHARED_MEM_SIZE_ISMAX_FILL getEnvVariable("SHARED_MEM_SIZE_ISMAXSHARED_MEM_SIZE_ISMAX_FILL", 1024)
#define GRID_SIZE_IMAGE_RESIZE getEnvVariable("GRID_SIZE_IMAGE_RESIZE", 256)
#define BLOCK_SIZE_IMAGE_RESIZE getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE", 256)
#define SHARED_MEM_SIZE_IMAGE_RESIZE getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE", 256)
#define GRID_SIZE_DIAG getEnvVariable("GRID_SIZE_DIAG", 256)
#define BLOCK_SIZE_DIAG getEnvVariable("BLOCK_SIZE_DIAG", 256)
#define SHARED_MEM_SIZE_DIAG getEnvVariable("SHARED_MEM_SIZE_DIAG", 256)
#define GRID_SIZE_CONFUSION_MATRIX getEnvVariable("GRID_SIZE_CONFUSION_MATRIX", 32)
#define BLOCK_SIZE_CONFUSION_MATRIX getEnvVariable("BLOCK_SIZE_CONFUSION_MATRIX", 32)
#define SHARED_MEM_SIZE_CONFUSION_MATRIX getEnvVariable("SHARED_MEM_SIZE_CONFUSION_MATRIX", 1024)
#define GRID_SIZE_TILE getEnvVariable("GRID_SIZE_TILE", 256)
#define BLOCK_SIZE_TILE getEnvVariable("BLOCK_SIZE_TILE", 512)
#define SHARED_MEM_SIZE_TILE getEnvVariable("SHARED_MEM_SIZE_TILE", 8192)
#define GRID_SIZE_DIAGONAL getEnvVariable("GRID_SIZE_DIAGONAL", 256)
#define BLOCK_SIZE_DIAGONAL getEnvVariable("BLOCK_SIZE_DIAGONAL", 512)
#define SHARED_MEM_SIZE_DIAGONAL getEnvVariable("SHARED_MEM_SIZE_DIAGONAL", 8192)
#define GRID_SIZE_TEAR getEnvVariable("GRID_SIZE_TEAR", 512)
#define BLOCK_SIZE_TEAR getEnvVariable("BLOCK_SIZE_TEAR", 512)
#define SHARED_MEM_SIZE_TEAR getEnvVariable("SHARED_MEM_SIZE_TEAR", 512)
#define GRID_SIZE_SORT_TENSOR_BY_DIM_KEY getEnvVariable("GRID_SIZE_SORT_TENSOR_BY_DIM_KEY", 256)
#define BLOCK_SIZE_SORT_TENSOR_BY_DIM_KEY getEnvVariable("BLOCK_SIZE_SORT_TENSOR_BY_DIM_KEY", 256)
#define SHARED_MEM_SIZE_SORT_TENSOR_BY_DIM_KEY getEnvVariable("SHARED_MEM_SIZE_SORT_TENSOR_BY_DIM_KEY", 256)
#define GRID_SIZE_SORT_TENSOR_ALONG_DIM_KEY getEnvVariable("GRID_SIZE_SORT_TENSOR_ALONG_DIM_KEY", 256)
#define BLOCK_SIZE_SORT_TENSOR_ALONG_DIM_KEY getEnvVariable("BLOCK_SIZE_SORT_TENSOR_ALONG_DIM_KEY", 256)
#define SHARED_MEM_SIZE_SORT_TENSOR_ALONG_DIM_KEY getEnvVariable("SHARED_MEM_SIZE_SORT_TENSOR_ALONG_DIM_KEY", 256)
#define GRID_SIZE_SORT_TENSOR_ALONG_DIM_VALUE getEnvVariable("GRID_SIZE_SORT_TENSOR_ALONG_DIM_VALUE", 256)
#define BLOCK_SIZE_SORT_TENSOR_ALONG_DIM_VALUE getEnvVariable("BLOCK_SIZE_SORT_TENSOR_ALONG_DIM_VALUE", 256)
#define SHARED_MEM_SIZE_SORT_TENSOR_ALONG_DIM_VALUE getEnvVariable("SHARED_MEM_SIZE_SORT_TENSOR_ALONG_DIM_VALUE", 256)
#define GRID_SIZE_SHUFFLE getEnvVariable("GRID_SIZE_SHUFFLE", 256)
#define BLOCK_SIZE_SHUFFLE getEnvVariable("BLOCK_SIZE_SHUFFLE", 512)
#define SHARED_MEM_SIZE_SHUFFLE getEnvVariable("SHARED_MEM_SIZE_SHUFFLE", 8192)
#define GRID_SIZE_PULLROWS getEnvVariable("GRID_SIZE_PULLROWS", 64)
#define BLOCK_SIZE_PULLROWS getEnvVariable("BLOCK_SIZE_PULLROWS", 256)
#define SHARED_MEM_SIZE_PULLROWS getEnvVariable("SHARED_MEM_SIZE_PULLROWS", 1024)
#define GRID_SIZE_PRESCAN_ARRAY_RECURSIVE getEnvVariable("GRID_SIZE_PRESCAN_ARRAY_RECURSIVE", 256)
#define BLOCK_SIZE_PRESCAN_ARRAY_RECURSIVE getEnvVariable("BLOCK_SIZE_PRESCAN_ARRAY_RECURSIVE", 256)
#define SHARED_MEM_SIZE_PRESCAN_ARRAY_RECURSIVE getEnvVariable("SHARED_MEM_SIZE_PRESCAN_ARRAY_RECURSIVE", 256)
#define GRID_SIZE_SCALAR_SCAN getEnvVariable("GRID_SIZE_SCALAR_SCAN", 256)
#define BLOCK_SIZE_SCALAR_SCAN getEnvVariable("BLOCK_SIZE_SCALAR_SCAN", 512)
#define SHARED_MEM_SIZE_SCALAR_SCAN getEnvVariable("SHARED_MEM_SIZE_SCALAR_SCAN", 8192)
#define GRID_SIZE_SCALAR_TAD getEnvVariable("GRID_SIZE_SCALAR_TAD", 256)
#define BLOCK_SIZE_SCALAR_TAD getEnvVariable("BLOCK_SIZE_SCALAR_TAD", 256)
#define SHARED_MEM_SIZE_SCALAR_TAD getEnvVariable("SHARED_MEM_SIZE_SCALAR_TAD", 16384)
#define GRID_SIZE_REDUCE_LONG getEnvVariable("GRID_SIZE_REDUCE_LONG", 256)
#define BLOCK_SIZE_REDUCE_LONG getEnvVariable("BLOCK_SIZE_REDUCE_LONG", 256)
#define SHARED_MEM_SIZE_REDUCE_LONG getEnvVariable("SHARED_MEM_SIZE_REDUCE_LONG", 1024)
#define GRID_SIZE_REDUCE_BOOL getEnvVariable("GRID_SIZE_REDUCE_BOOL", 256)
#define BLOCK_SIZE_REDUCE_BOOL getEnvVariable("BLOCK_SIZE_REDUCE_BOOL", 256)
#define SHARED_MEM_SIZE_REDUCE_BOOL getEnvVariable("SHARED_MEM_SIZE_REDUCE_BOOL", 1024)
#define GRID_SIZE_AVERAGE getEnvVariable("GRID_SIZE_AVERAGE", 256)
#define BLOCK_SIZE_AVERAGE getEnvVariable("BLOCK_SIZE_AVERAGE", 256)
#define SHARED_MEM_SIZE_AVERAGE getEnvVariable("SHARED_MEM_SIZE_AVERAGE", 4096)
#define GRID_SIZE_ACCUMULATE getEnvVariable("GRID_SIZE_ACCUMULATE", 256)
#define BLOCK_SIZE_ACCUMULATE getEnvVariable("BLOCK_SIZE_ACCUMULATE", 256)
#define SHARED_MEM_SIZE_ACCUMULATE getEnvVariable("SHARED_MEM_SIZE_ACCUMULATE", 8192)
#define GRID_SIZE_TRANSFORM_SCAN getEnvVariable("GRID_SIZE_TRANSFORM_SCAN", 256)
#define BLOCK_SIZE_TRANSFORM_SCAN getEnvVariable("BLOCK_SIZE_TRANSFORM_SCAN", 256)
#define SHARED_MEM_SIZE_TRANSFORM_SCAN getEnvVariable("SHARED_MEM_SIZE_TRANSFORM_SCAN", 1024)
#define GRID_SIZE_SUMMARY_STATS getEnvVariable("GRID_SIZE_SUMMARY_STATS", 256)
#define BLOCK_SIZE_SUMMARY_STATS getEnvVariable("BLOCK_SIZE_SUMMARY_STATS", SD_CUDA_BLOCK_SIZE)
#define SHARED_MEM_SIZE_SUMMARY_STATS getEnvVariable("SHARED_MEM_SIZE_SUMMARY_STATS", 1024)
#define GRID_SIZE_REDUCE_FLOAT getEnvVariable("GRID_SIZE_REDUCE_FLOAT", 256)
#define BLOCK_SIZE_REDUCE_FLOAT getEnvVariable("BLOCK_SIZE_REDUCE_FLOAT", 256)
#define SHARED_MEM_SIZE_REDUCE_FLOAT getEnvVariable("SHARED_MEM_SIZE_REDUCE_FLOAT", 256)
#define GRID_SIZE_SCALAR_BOOL getEnvVariable("GRID_SIZE_SCALAR_BOOL", 256)
#define BLOCK_SIZE_SCALAR_BOOL getEnvVariable("BLOCK_SIZE_SCALAR_BOOL", 256)
#define SHARED_MEM_SIZE_SCALAR_BOOL getEnvVariable("SHARED_MEM_SIZE_SCALAR_BOOL", 256)
#define GRID_SIZE_SCALAR_SAME getEnvVariable("GRID_SIZE_SCALAR_SAME", 256)
#define BLOCK_SIZE_SCALAR_SAME getEnvVariable("BLOCK_SIZE_SCALAR_SAME", 256)
#define SHARED_MEM_SIZE_SCALAR_SAME getEnvVariable("SHARED_MEM_SIZE_SCALAR_SAME", 256)
#define GRID_SIZE_SCALAR_LONG getEnvVariable("GRID_SIZE_SCALAR_LONG", 256)
#define BLOCK_SIZE_SCALAR_LONG getEnvVariable("BLOCK_SIZE_SCALAR_LONG", 256)
#define SHARED_MEM_SIZE_SCALAR_LONG getEnvVariable("SHARED_MEM_SIZE_SCALAR_LONG", 256)
#define GRID_SIZE_REDUCE_3 getEnvVariable("GRID_SIZE_REDUCE_3", 256)
#define BLOCK_SIZE_REDUCE_3 getEnvVariable("BLOCK_SIZE_REDUCE_3", 256)
#define SHARED_MEM_SIZE_REDUCE_3 getEnvVariable("SHARED_MEM_SIZE_REDUCE_3", 256)
#define GRID_SIZE_PAIRWISE_TRANSFORMS getEnvVariable("GRID_SIZE_PAIRWISE_TRANSFORMS", 256)
#define BLOCK_SIZE_PAIRWISE_TRANSFORMS getEnvVariable("BLOCK_SIZE_PAIRWISE_TRANSFORMS", 256)
#define SHARED_MEM_SIZE_PAIRWISE_TRANSFORMS getEnvVariable("SHARED_MEM_SIZE_PAIRWISE_TRANSFORMS", 256)
#define GRID_SIZE_BROADCAST getEnvVariable("GRID_SIZE_BROADCAST", 256)
#define BLOCK_SIZE_BROADCAST getEnvVariable("BLOCK_SIZE_BROADCAST", 256)
#define SHARED_MEM_SIZE_BROADCAST getEnvVariable("SHARED_MEM_SIZE_BROADCAST", 1024)
#define GRID_SIZE_BROADCAST_INT getEnvVariable("GRID_SIZE_BROADCAST_INT", 256)
#define BLOCK_SIZE_BROADCAST_INT getEnvVariable("BLOCK_SIZE_BROADCAST_INT", 256)
#define SHARED_MEM_SIZE_BROADCAST_INT getEnvVariable("SHARED_MEM_SIZE_BROADCAST_INT", 1024)
#define GRID_SIZE_BROADCAST_BOOL getEnvVariable("GRID_SIZE_BROADCAST_BOOL", 256)
#define BLOCK_SIZE_BROADCAST_BOOL getEnvVariable("BLOCK_SIZE_BROADCAST_BOOL", 256)
#define SHARED_MEM_SIZE_BROADCAST_BOOL getEnvVariable("SHARED_MEM_SIZE_BROADCAST_BOOL", 1024)
#define GRID_SIZE_MATRIX_MULTIPLY getEnvVariable("GRID_SIZE_MATRIX_MULTIPLY", 256)
#define BLOCK_SIZE_MATRIX_MULTIPLY getEnvVariable("BLOCK_SIZE_MATRIX_MULTIPLY", 256)
#define SHARED_MEM_SIZE_MATRIX_MULTIPLY getEnvVariable("SHARED_MEM_SIZE_MATRIX_MULTIPLY", 256)
#define GRID_SIZE_LOG_ABS_DETERMINANT getEnvVariable("GRID_SIZE_LOG_ABS_DETERMINANT", 256)
#define BLOCK_SIZE_LOG_ABS_DETERMINANT getEnvVariable("BLOCK_SIZE_LOG_ABS_DETERMINANT", 256)
#define SHARED_MEM_SIZE_LOG_ABS_DETERMINANT getEnvVariable("SHARED_MEM_SIZE_LOG_ABS_DETERMINANT", 1024)
#define GRID_SIZE_DIAG_PART getEnvVariable("GRID_SIZE_DIAG_PART ", 256)
#define BLOCK_SIZE_DIAG_PART getEnvVariable("BLOCK_SIZE_DIAG_PART ", 512)
#define SHARED_MEM_SIZE_DIAG_PART getEnvVariable("SHARED_MEM_SIZE_DIAG_PART ", 8192)
#define GRID_SIZE_RANDOM getEnvVariable("GRID_SIZE_RANDOM ", 512)
#define BLOCK_SIZE_RANDOM getEnvVariable("BLOCK_SIZE_RANDOM ", 512)
#define SHARED_MEM_SIZE_RANDOM getEnvVariable("SHARED_MEM_SIZE_RANDOM ", 32768)
#define GRID_SIZE_LAMBDA getEnvVariable("GRID_SIZE_LAMBDA", 256)
#define BLOCK_SIZE_LAMBDA getEnvVariable("BLOCK_SIZE_LAMBDA", 512)
#define SHARED_MEM_SIZE_LAMBDA getEnvVariable("SHARED_MEM_SIZE_LAMBDA", 8192)
#define GRID_SIZE_IM2COL getEnvVariable("GRID_SIZE_IM2COL", 256)
#define BLOCK_SIZE_IM2COL getEnvVariable("BLOCK_SIZE_IM2COL", 512)
#define SHARED_MEM_SIZE_IM2COL getEnvVariable("SHARED_MEM_SIZE_IM2COL", 8192)
#define GRID_SIZE_COL2IM getEnvVariable("GRID_SIZE_COL2IM", 256)
#define BLOCK_SIZE_COL2IM getEnvVariable("BLOCK_SIZE_COL2IM", 512)
#define SHARED_MEM_SIZE_COL2IM getEnvVariable("SHARED_MEM_SIZE_COL2IM", 8192)
#define GRID_SIZE_GEMV getEnvVariable("GRID_SIZE_GEMV", 256)
#define BLOCK_SIZE_GEMV getEnvVariable("BLOCK_SIZE_GEMV", 512)
#define SHARED_MEM_SIZE_GEMV getEnvVariable("SHARED_MEM_SIZE_GEMV", 8192)
#define GRID_SIZE_ADDBIAS getEnvVariable("GRID_SIZE_ADDBIAS", 256)
#define BLOCK_SIZE_ADDBIAS getEnvVariable("BLOCK_SIZE_ADDBIAS", 512)
#define SHARED_MEM_SIZE_ADDBIAS getEnvVariable("SHARED_MEM_SIZE_ADDBIAS", 8192)
#define GRID_SIZE_POOLING getEnvVariable("GRID_SIZE_POOLING", 256)
#define BLOCK_SIZE_POOLING getEnvVariable("BLOCK_SIZE_POOLING", 512)
#define SHARED_MEM_SIZE_POOLING getEnvVariable("SHARED_MEM_SIZE_POOLING", 8192)
#define GRID_SIZE_COL2VOL getEnvVariable("GRID_SIZE_COL2VOL", 256)
#define BLOCK_SIZE_COL2VOL getEnvVariable("BLOCK_SIZE_COL2VOL", 512)
#define SHARED_MEM_SIZE_COL2VOL getEnvVariable("SHARED_MEM_SIZE_COL2VOL", 8192)
#define GRID_SIZE_VOL2COL getEnvVariable("GRID_SIZE_VOL2COL", 256)
#define BLOCK_SIZE_VOL2COL getEnvVariable("BLOCK_SIZE_VOL2COL", 512)
#define SHARED_MEM_SIZE_VOL2COL getEnvVariable("SHARED_MEM_SIZE_VOL2COL", 8192)
#define GRID_SIZE_UPSAMPLING getEnvVariable("GRID_SIZE_UPSAMPLING", 256)
#define BLOCK_SIZE_UPSAMPLING getEnvVariable("BLOCK_SIZE_UPSAMPLING", 512)
#define SHARED_MEM_SIZE_UPSAMPLING getEnvVariable("SHARED_MEM_SIZE_UPSAMPLING", 8192)
#define GRID_SIZE_UPSAMPLING getEnvVariable("GRID_SIZE_PRELU", 256)
#define BLOCK_SIZE_UPSAMPLING getEnvVariable("BLOCK_SIZE_PRELU", 512)
#define SHARED_MEM_SIZE_UPSAMPLING getEnvVariable("SHARED_MEM_SIZE_PRELU", 512)
#define GRID_SIZE_UPSAMPLING getEnvVariable("GRID_SIZE_ADJUST", 256)
#define BLOCK_SIZE_UPSAMPLING getEnvVariable("BLOCK_SIZE_ADJUST", 512)
#define SHARED_MEM_SIZE_UPSAMPLING getEnvVariable("SHARED_MEM_SIZE_ADJUST", 512)
#define GRID_SIZE_BATCHNORM getEnvVariable("GRID_SIZE_BATCHNORM", 256)
#define BLOCK_SIZE_BATCHNORM getEnvVariable("BLOCK_SIZE_BATCHNORM", 512)
#define SHARED_MEM_SIZE_BATCHNORM getEnvVariable("SHARED_MEM_SIZE_BATCHNORM", 512)
#define GRID_SIZE_COMPARE_AND_BITPACK getEnvVariable("GRID_SIZE_COMPARE_AND_BITPACK", 256)
#define BLOCK_SIZE_COMPARE_AND_BITPACK getEnvVariable("BLOCK_SIZE_COMPARE_AND_BITPACK", 512)
#define SHARED_MEM_SIZE_COMPARE_AND_BITPACK getEnvVariable("SHARED_MEM_SIZE_COMPARE_AND_BITPACK", 512)
#define GRID_SIZE_CONFUSION_MATRIX getEnvVariable("GRID_SIZE_CONFUSION_MATRIX", 256)
#define BLOCK_SIZE_CONFUSION_MATRIX getEnvVariable("BLOCK_SIZE_CONFUSION_MATRIX", 512)
#define SHARED_MEM_SIZE_CONFUSION_MATRIX getEnvVariable("SHARED_MEM_SIZE_CONFUSION_MATRIX", 1024)
#define GRID_SIZE_CLIP getEnvVariable("GRID_SIZE_CLIP", 256)
#define BLOCK_SIZE_CLIP getEnvVariable("BLOCK_SIZE_CLIP", 512)
#define SHARED_MEM_SIZE_CLIP getEnvVariable("SHARED_MEM_SIZE_CLIP", 8192)
#define GRID_SIZE_CROSS getEnvVariable("GRID_SIZE_CROSS", 256)
#define BLOCK_SIZE_CROSS getEnvVariable("BLOCK_SIZE_CROSS", 512)
#define SHARED_MEM_SIZE_CROSS getEnvVariable("SHARED_MEM_SIZE_CROSS", 8192)
#define GRID_SIZE_BETA_INC getEnvVariable("GRID_SIZE_BETA_INC", 256)
#define BLOCK_SIZE_BETA_INC getEnvVariable("BLOCK_SIZE_BETA_INC", 512)
#define SHARED_MEM_SIZE_BETA_INC getEnvVariable("SHARED_MEM_SIZE_BETA_INC", 8192)
#define GRID_SIZE_ADJUST getEnvVariable("GRID_SIZE_ADJUST", 256)
#define BLOCK_SIZE_ADJUST getEnvVariable("BLOCK_SIZE_ADJUST", 512)
#define SHARED_MEM_SIZE_ADJUST getEnvVariable("SHARED_MEM_SIZE_ADJUST", 8192)
#define GRID_SIZE_CONCAT getEnvVariable("GRID_SIZE_CONCAT", 256)
#define BLOCK_SIZE_CONCAT getEnvVariable("BLOCK_SIZE_CONCAT", 512)
#define SHARED_MEM_SIZE_CONCAT getEnvVariable("SHARED_MEM_SIZE_CONCAT", 8192)
#define GRID_SIZE_DEPTH_TO_SPACE getEnvVariable("GRID_SIZE_DEPTH_TO_SPACE", 512)
#define BLOCK_SIZE_DEPTH_TO_SPACE getEnvVariable("BLOCK_SIZE_DEPTH_TO_SPACE", 512)
#define SHARED_MEM_SIZE_DEPTH_TO_SPACE getEnvVariable("SHARED_MEM_SIZE_DEPTH_TO_SPACE", 1024)
#define GRID_SIZE_PRELU getEnvVariable("GRID_SIZE_PRELU", 512)
#define BLOCK_SIZE_PRELU getEnvVariable("BLOCK_SIZE_PRELU", 512)
#define SHARED_MEM_SIZE_PRELU getEnvVariable("SHARED_MEM_SIZE_PRELU", 1024)
#define GRID_SIZE_HISTOGRAM getEnvVariable("GRID_SIZE_HISTOGRAM", 512)
#define BLOCK_SIZE_HISTOGRAM getEnvVariable("BLOCK_SIZE_HISTOGRAM", 512)
#define SHARED_MEM_SIZE_HISTOGRAM getEnvVariable("SHARED_MEM_SIZE_HISTOGRAM", 1024)
#define GRID_SIZE_DILATION getEnvVariable("GRID_SIZE_DILATION", 512)
#define BLOCK_SIZE_DILATION getEnvVariable("BLOCK_SIZE_DILATION", 512)
#define SHARED_MEM_SIZE_DILATION getEnvVariable("SHARED_MEM_SIZE_DILATION", 1024)
#define GRID_SIZE_DROPOUT getEnvVariable("GRID_SIZE_DROPOUT", 256)
#define BLOCK_SIZE_DROPOUT getEnvVariable("BLOCK_SIZE_DROPOUT", 128)
#define SHARED_MEM_SIZE_DROPOUT getEnvVariable("SHARED_MEM_SIZE_DROPOUT", 1024)
#define GRID_SIZE_EXTRACT_PATCHES getEnvVariable("GRID_SIZE_EXTRACT_PATCHES", 128)
#define BLOCK_SIZE_EXTRACT_PATCHES getEnvVariable("BLOCK_SIZE_EXTRACT_PATCHES", 128)
#define SHARED_MEM_SIZE_EXTRACT_PATCHES getEnvVariable("SHARED_MEM_SIZE_EXTRACT_PATCHES", 1024)
#define GRID_SIZE_FAKE_QUANTIZATION getEnvVariable("GRID_SIZE_FAKE_QUANTIZATION", 128)
#define BLOCK_SIZE_FAKE_QUANTIZATION getEnvVariable("BLOCK_SIZE_FAKE_QUANTIZATION", 256)
#define SHARED_MEM_SIZE_FAKE_QUANTIZATION getEnvVariable("SHARED_MEM_SIZE_FAKE_QUANTIZATION", 256)
#define GRID_SIZE_FLATTEN getEnvVariable("GRID_SIZE_FLATTEN", 256)
#define BLOCK_SIZE_FLATTEN getEnvVariable("BLOCK_SIZE_FLATTEN", 512)
#define SHARED_MEM_SIZE_FLATTEN getEnvVariable("SHARED_MEM_SIZE_FLATTEN", 8192)
#define GRID_SIZE_GATHER_LINEAR getEnvVariable("GRID_SIZE_GATHER_LINEAR", 128)
#define BLOCK_SIZE_GATHER_LINEAR getEnvVariable("BLOCK_SIZE_GATHER_LINEAR", 256)
#define SHARED_MEM_SIZE_GATHER_LINEAR getEnvVariable("SHARED_MEM_SIZE_GATHER_LINEAR", 1024)
#define GRID_SIZE_GATHER getEnvVariable("GRID_SIZE_GATHER", 128)
#define BLOCK_SIZE_GATHER getEnvVariable("BLOCK_SIZE_GATHER", 256)
#define SHARED_MEM_SIZE_GATHER getEnvVariable("SHARED_MEM_SIZE_GATHER", 1024)
#define GRID_SIZE_GATHERND getEnvVariable("GRID_SIZE_GATHERND", 128)
#define BLOCK_SIZE_GATHERND getEnvVariable("BLOCK_SIZE_GATHERND", 256)
#define SHARED_MEM_SIZE_GATHERND getEnvVariable("SHARED_MEM_SIZE_GATHERND", 1024)
#define GRID_SIZE_HAMMING getEnvVariable("GRID_SIZE_HAMMING", 128)
#define BLOCK_SIZE_HAMMING getEnvVariable("BLOCK_SIZE_HAMMING",SD_CUDA_BLOCK_SIZE)
#define SHARED_MEM_SIZE_HAMMING getEnvVariable("SHARED_MEM_SIZE_HAMMING", 1024)
#define GRID_SIZE_HASHCODE_SPLIT getEnvVariable("GRID_SIZE_HASHCODE_SPLIT", 128)
#define BLOCK_SIZE_HASHCODE_SPLIT getEnvVariable("BLOCK_SIZE_HASHCODE_SPLIT",SD_CUDA_BLOCK_SIZE)
#define SHARED_MEM_SIZE_HASHCODE_SPLIT getEnvVariable("SHARED_MEM_SIZE_HASHCODE_SPLIT", 1024)
#define GRID_SIZE_HASHCODE_INTERNAL getEnvVariable("GRID_SIZE_HASHCODE_INTERNAL", 128)
#define BLOCK_SIZE_HASHCODE_INTERNAL getEnvVariable("BLOCK_SIZE_HASHCODE_INTERNAL",SD_CUDA_BLOCK_SIZE)
#define SHARED_MEM_SIZE_HASHCODE_INTERNAL getEnvVariable("SHARED_MEM_SIZE_HASHCODE_INTERNAL", 1024)
#define GRID_SIZE_HASHCODE_LAST getEnvVariable("GRID_SIZE_HASHCODE_LAST", 1)
#define BLOCK_SIZE_HASHCODE_LAST getEnvVariable("BLOCK_SIZE_HASHCODE_LAST",1)
#define SHARED_MEM_SIZE_HASHCODE_LAST getEnvVariable("SHARED_MEM_SIZE_HASHCODE_LAST", 128)
#define GRID_SIZE_HISTOGRAM_FIXED_WIDTH getEnvVariable("GRID_SIZE_HISTOGRAM_FIXED_WIDTH", 256)
#define BLOCK_SIZE_HISTOGRAM_FIXED_WIDTH getEnvVariable("BLOCK_SIZE_HISTOGRAM_FIXED_WIDTH",256)
#define SHARED_MEM_SIZE_HISTOGRAM_FIXED_WIDTH getEnvVariable("SHARED_MEM_SIZE_HISTOGRAM_FIXED_WIDTH", 1024)
#define GRID_SIZE_DRAW_BOUNDING_BOXES getEnvVariable("GRID_SIZE_DRAW_BOUNDING_BOXES", 128)
#define BLOCK_SIZE_DRAW_BOUNDING_BOXES getEnvVariable("BLOCK_SIZE_DRAW_BOUNDING_BOXES",128)
#define SHARED_MEM_SIZE_DRAW_BOUNDING_BOXES getEnvVariable("SHARED_MEM_SIZE_DRAW_BOUNDING_BOXES", 1024)
#define GRID_SIZE_IMAGE_RESIZE getEnvVariable("GRID_SIZE_IMAGE_RESIZE", 256)
#define BLOCK_SIZE_IMAGE_RESIZE getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE",256)
#define SHARED_MEM_SIZE_IMAGE_RESIZE getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE", 256)
#define GRID_SIZE_IMAGE_RESIZE_INTERP_WEIGHTS getEnvVariable("GRID_SIZE_IMAGE_RESIZE_INTERP_WEIGHTS", 256)
#define BLOCK_SIZE_IMAGE_RESIZE_INTERP_WEIGHTS getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE_INTERP_WEIGHTS",512)
#define SHARED_MEM_SIZE_IMAGE_RESIZE_INTERP_WEIGHTS getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE_INTERP_WEIGHTS", 512)
#define GRID_SIZE_IMAGE_RESIZE_INIT_COEFFS getEnvVariable("GRID_SIZE_IMAGE_RESIZE_INIT_COEFFS", 128)
#define BLOCK_SIZE_IMAGE_RESIZE_INIT_COEFFS getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE_INIT_COEFFS",128)
#define SHARED_MEM_SIZE_IMAGE_RESIZE_INIT_COEFFS getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE_INIT_COEFFS", 128)
#define GRID_SIZE_IMAGE_RESIZE_COEFFS_ACCUM getEnvVariable("GRID_SIZE_IMAGE_RESIZE_COEFFS_ACCUM", 128)
#define BLOCK_SIZE_IMAGE_RESIZE_COEFFS_ACCUM getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE_COEFFS_ACCUM",128)
#define SHARED_MEM_SIZE_IMAGE_RESIZE_COEFFS_ACCUM getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE_COEFFS_ACCUM", 512)
#define GRID_SIZE_IMAGE_RESIZE_BICUBIC getEnvVariable("GRID_SIZE_IMAGE_RESIZE_BICUBIC", 128)
#define BLOCK_SIZE_IMAGE_RESIZE_BICUBIC getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE_BICUBIC",1)
#define SHARED_MEM_SIZE_IMAGE_RESIZE_BICUBIC getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE_BICUBIC", 512)
#define GRID_SIZE_IMAGE_RESIZE_FILL_INTERP getEnvVariable("GRID_SIZE_IMAGE_RESIZE_FILL_INTERP", 128)
#define BLOCK_SIZE_IMAGE_RESIZE_FILL_INTERP getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE_FILL_INTERP",128)
#define SHARED_MEM_SIZE_IMAGE_RESIZE_FILL_INTERP getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE_FILL_INTERP", 256)
#define GRID_SIZE_IMAGE_RESIZE_CROP_AND_RESIZE getEnvVariable("GRID_SIZE_IMAGE_RESIZE_CROP_AND_RESIZE", 128)
#define BLOCK_SIZE_IMAGE_RESIZE_CROP_AND_RESIZE getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE_CROP_AND_RESIZE",128)
#define SHARED_MEM_SIZE_IMAGE_RESIZE_CROP_AND_RESIZE getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE_CROP_AND_RESIZE", 256)
#define GRID_SIZE_IMAGE_RESIZE_V2_GATHER getEnvVariable("GRID_SIZE_IMAGE_RESIZE_V2_GATHER", 128)
#define BLOCK_SIZE_IMAGE_RESIZE_V2_GATHER getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE_V2_GATHER",128)
#define SHARED_MEM_SIZE_IMAGE_RESIZE_V2_GATHER getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE_V2_GATHER", 256)
#define GRID_SIZE_IMAGE_SUPPRESS_SCORES getEnvVariable("GRID_SIZE_IMAGE_SUPPRESS_SCORES", 128)
#define BLOCK_SIZE_IMAGE_SUPPRESS_SCORES getEnvVariable("BLOCK_SIZE_IMAGE_SUPPRESS_SCORES",128)
#define SHARED_MEM_SIZE_IMAGE_SUPPRESS_SCORES getEnvVariable("SHARED_MEM_SIZE_IMAGE_SUPPRESS_SCORES", 128)
#define GRID_SIZE_IMAGE_SUPPRESS_SELECT getEnvVariable("GRID_SIZE_IMAGE_SUPPRESS_SELECT", 128)
#define BLOCK_SIZE_IMAGE_SUPPRESS_SELECT getEnvVariable("BLOCK_SIZE_IMAGE_SUPPRESS_SELECT",256)
#define SHARED_MEM_SIZE_IMAGE_SUPPRESS_SELECT getEnvVariable("SHARED_MEM_SIZE_IMAGE_SUPPRESS_SELECT", 1024)
#define GRID_SIZE_IMAGE_SUPPRESS_NONMAX_OVERLAP getEnvVariable("GRID_SIZE_IMAGE_SUPPRESS_NONMAX_OVERLAP", 1)
#define BLOCK_SIZE_IMAGE_SUPPRESS_NONMAX_OVERLAP getEnvVariable("BLOCK_SIZE_IMAGE_SUPPRESS_NONMAX_OVERLAP",1)
#define SHARED_MEM_SIZE_IMAGE_SUPPRESS_NONMAX_OVERLAP getEnvVariable("SHARED_MEM_SIZE_IMAGE_SUPPRESS_NONMAX_OVERLAP", 1024)
#define GRID_SIZE_IMAGE_HELPERS_TRIPLE getEnvVariable("GRID_SIZE_IMAGE_HELPERS_TRIPLE", 256)
#define BLOCK_SIZE_IMAGE_HELPERS_TRIPLE getEnvVariable("BLOCK_SIZE_IMAGE_HELPERS_TRIPLE",256)
#define SHARED_MEM_SIZE_IMAGE_HELPERS_TRIPLE getEnvVariable("SHARED_MEM_SIZE_IMAGE_HELPERS_TRIPLE", 8192)
#define GRID_SIZE_IMAGE_HELPERS getEnvVariable("GRID_SIZE_IMAGE_HELPERS", 256)
#define BLOCK_SIZE_IMAGE_HELPERS getEnvVariable("BLOCK_SIZE_IMAGE_HELPERS",256)
#define SHARED_MEM_SIZE_GRID_SIZE_IMAGE_HELPERS getEnvVariable("SHARED_MEM_SIZE_GRID_SIZE_IMAGE_HELPERS", 8192)
#define GRID_SIZE_LRN getEnvVariable("GRID_SIZE_LRN", 256)
#define BLOCK_SIZE_LRN getEnvVariable("BLOCK_SIZE_LRN",256)
#define SHARED_MEM_SIZE_LRN getEnvVariable("SHARED_MEM_SIZE_LRN", 8192)
#define GRID_SIZE_LSTSQ_REG getEnvVariable("GRID_SIZE_LSTSQ_REG", 256)
#define BLOCK_SIZE_LSTSQ_REG getEnvVariable("BLOCK_SIZE_LSTSQ_REG",256)
#define SHARED_MEM_SIZE_LSTSQ_REG getEnvVariable("SHARED_MEM_SIZE_LSTSQ_REG", 128)
#define GRID_SIZE_LUP getEnvVariable("GRID_SIZE_LUP", 256)
#define GRID_SIZE_LUP getEnvVariable("GRID_SIZE_LUP",256)
#define SHARED_MEM_SIZE_LUP getEnvVariable("SHARED_MEM_SIZE_LUP", 512)
#define GRID_SIZE_LUP_LOW getEnvVariable("GRID_SIZE_LUP_LOW", 256)
#define BLOCK_SIZE_LUP_LOW getEnvVariable("BLOCK_SIZE_LUP_LOW",256)
#define SHARED_MEM_SIZE_LUP_LOW getEnvVariable("SHARED_MEM_SIZE_LUP_LOW", 512)
#define GRID_SIZE_MATRIX_SET_DIAG getEnvVariable("GRID_SIZE_MATRIX_SET_DIAG", 256)
#define BLOCK_SIZE_MATRIX_SET_DIAG getEnvVariable("BLOCK_SIZE_MATRIX_SET_DIAG",256)
#define SHARED_MEM_SIZE_MATRIX_SET_DIAG getEnvVariable("SHARED_MEM_SIZE_MATRIX_SET_DIAG", 512)
#define GRID_SIZE_MERGE getEnvVariable("GRID_SIZE_MERGE", 256)
#define BLOCK_SIZE_MERGE getEnvVariable("BLOCK_SIZE_MERGE",256)
#define SHARED_MEM_SIZE_MERGE getEnvVariable("SHARED_MEM_SIZE_MERGE", 512)
#define GRID_SIZE_MESHGRID getEnvVariable("GRID_SIZE_MESHGRID", 256)
#define BLOCK_SIZE_MESHGRID getEnvVariable("BLOCK_SIZE_MESHGRID",256)
#define SHARED_MEM_SIZE_MESHGRID getEnvVariable("SHARED_MEM_SIZE_MESHGRID", 1024)
#define GRID_SIZE_NTH_ELEMENT_FILL getEnvVariable("GRID_SIZE_NTH_ELEMENT_FILL", 32)
#define BLOCK_SIZE_NTH_ELEMENT_FILL getEnvVariable("BLOCK_SIZE_NTH_ELEMENT_FILL",64)
#define SHARED_MEM_SIZE_NTH_ELEMENT_FILL getEnvVariable("SHARED_MEM_SIZE_NTH_ELEMENT_FILL", 1024)
#define GRID_SIZE_ONE_HOT getEnvVariable("GRID_SIZE_ONE_HOT", 32)
#define BLOCK_SIZE_ONE_HOT getEnvVariable("BLOCK_SIZE_ONE_HOT",64)
#define SHARED_MEM_SIZE_ONE_HOT getEnvVariable("SHARED_MEM_SIZE_ONE_HOT", 1024)
#define GRID_SIZE_PAD getEnvVariable("GRID_SIZE_PAD", 32)
#define BLOCK_SIZE_PAD getEnvVariable("BLOCK_SIZE_PAD",64)
#define SHARED_MEM_SIZE_PAD getEnvVariable("SHARED_MEM_SIZE_PAD", 1024)
#define GRID_SIZE_MIRROR_PAD_LINEAR getEnvVariable("GRID_SIZE_MIRROR_PAD_LINEAR", 256)
#define BLOCK_SIZE_MIRROR_PAD_LINEAR getEnvVariable("BLOCK_SIZE_MIRROR_PAD_LINEAR",512)
#define SHARED_MEM_SIZE_MIRROR_PAD_LINEAR getEnvVariable("SHARED_MEM_SIZE_MIRROR_PAD_LINEAR", 256)
#define GRID_SIZE_MIRROR_PAD_TAD getEnvVariable("GRID_SIZE_MIRROR_PAD_TAD", 256)
#define BLOCK_SIZE_MIRROR_PAD_TAD getEnvVariable("BLOCK_SIZE_MIRROR_PAD_TAD",512)
#define SHARED_MEM_SIZE_MIRROR_PAD_TAD getEnvVariable("SHARED_MEM_SIZE_MIRROR_PAD_TAD", 256)
#define GRID_SIZE_PERCENTILE getEnvVariable("GRID_SIZE_PERCENTILE", 256)
#define BLOCK_SIZE_PERCENTILE getEnvVariable("BLOCK_SIZE_PERCENTILE",512)
#define SHARED_MEM_SIZE_PERCENTILE getEnvVariable("SHARED_MEM_SIZE_PERCENTILE", 1024)
#define GRID_SIZE_POLYGAMMA getEnvVariable("GRID_SIZE_POLYGAMMA", 256)
#define BLOCK_SIZE_POLYGAMMA getEnvVariable("BLOCK_SIZE_POLYGAMMA",512)
#define SHARED_MEM_SIZE_POLYGAMMA getEnvVariable("SHARED_MEM_SIZE_POLYGAMMA", 1024)
#define GRID_SIZE_PREFIX getEnvVariable("GRID_SIZE_PREFIX", 256)
#define BLOCK_SIZE_PREFIX getEnvVariable("BLOCK_SIZE_PREFIX",512)
#define SHARED_MEM_SIZE_PREFIX getEnvVariable("SHARED_MEM_SIZE_PREFIX", 1024)
#define GRID_SIZE_PRINT getEnvVariable("GRID_SIZE_PRINT", 1)
#define BLOCK_SIZE_PRINT getEnvVariable("BLOCK_SIZE_PRINT",1)
#define SHARED_MEM_SIZE_PRINT getEnvVariable("SHARED_MEM_SIZE_PRINT", 1024)
#define GRID_SIZE_QR getEnvVariable("GRID_SIZE_QR", 28)
#define BLOCK_SIZE_QR getEnvVariable("BLOCK_SIZE_QR",28)
#define SHARED_MEM_SIZE_QR getEnvVariable("SHARED_MEM_SIZE_QR", 28)
#define GRID_SIZE_RANDOM_GAMMA getEnvVariable("GRID_SIZE_RANDOM_GAMMA", 128)
#define BLOCK_SIZE_RANDOM_GAMMA getEnvVariable("BLOCK_SIZE_RANDOM_GAMMA",128)
#define SHARED_MEM_SIZE_RANDOM_GAMMA getEnvVariable("SHARED_MEM_SIZE_RANDOM_GAMMA", 256)
#define GRID_SIZE_RANDOM_POISSON getEnvVariable("GRID_SIZE_RANDOM_POISSON", 128)
#define BLOCK_SIZE_RANDOM_POISSON getEnvVariable("BLOCK_SIZE_RANDOM_POISSON",256)
#define SHARED_MEM_SIZE_RANDOM_POISSON getEnvVariable("SHARED_MEM_SIZE_RANDOM_POISSON", 256)
#define GRID_SIZE_RANDOM_UNIFORM getEnvVariable("GRID_SIZE_RANDOM_UNIFORM", 128)
#define BLOCK_SIZE_RANDOM_UNIFORM getEnvVariable("BLOCK_SIZE_RANDOM_UNIFORM",128)
#define SHARED_MEM_SIZE_RANDOM_UNIFORM getEnvVariable("SHARED_MEM_SIZE_RANDOM_UNIFORM", 128)
#define GRID_SIZE_RANDOM_SHUFFLE_FISHER getEnvVariable("GRID_SIZE_RANDOM_SHUFFLE_FISHER", 128)
#define BLOCK_SIZE_RANDOM_SHUFFLE_FISHER getEnvVariable("BLOCK_SIZE_RANDOM_SHUFFLE_FISHER",128)
#define SHARED_MEM_SIZE_RANDOM_SHUFFLE_FISHER getEnvVariable("SHARED_MEM_SIZE_RANDOM_SHUFFLE_FISHER", 128)
#define GRID_SIZE_RANDOM_SHUFFLE_MERGE getEnvVariable("GRID_SIZE_RANDOM_SHUFFLE_MERGE", 128)
#define BLOCK_SIZE_RANDOM_SHUFFLE_MERGE getEnvVariable("BLOCK_SIZE_RANDOM_SHUFFLE_MERGE",128)
#define SHARED_MEM_SIZE_RANDOM_SHUFFLE_MERGE getEnvVariable("SHARED_MEM_SIZE_RANDOM_SHUFFLE_MERGE", 128)
#define GRID_SIZE_RANGE getEnvVariable("GRID_SIZE_RANGE", 512)
#define BLOCK_SIZE_RANGE getEnvVariable("BLOCK_SIZE_RANGE",512)
#define SHARED_MEM_SIZE_RANGE getEnvVariable("SHARED_MEM_SIZE_RANGE", 2048)
#define GRID_SIZE_REVERSE getEnvVariable("GRID_SIZE_REVERSE", 256)
#define BLOCK_SIZE_REVERSE getEnvVariable("BLOCK_SIZE_REVERSE",512)
#define SHARED_MEM_SIZE_REVERSE getEnvVariable("SHARED_MEM_SIZE_REVERSEE", 8192)
#define GRID_SIZE_ROLL getEnvVariable("GRID_SIZE_ROLL", 1)
#define BLOCK_SIZE_ROLL getEnvVariable("BLOCK_SIZE_ROLL",1)
#define SHARED_MEM_SIZE_ROLL getEnvVariable("SHARED_MEM_SIZE_ROLL", 1024)
#define GRID_SIZE_BATCH_TO_SPACE_ND getEnvVariable("GRID_SIZE_BATCH_TO_SPACE_ND", 1)
#define BLOCK_SIZE_BATCH_TO_SPACE_ND getEnvVariable("BLOCK_SIZE_BATCH_TO_SPACE_ND",1)
#define SHARED_MEM_SIZE_BATCH_TO_SPACE_ND getEnvVariable("SHARED_MEM_SIZE_BATCH_TO_SPACE_ND", 1024)
#define GRID_SIZE_SPACE_TO_BATCH getEnvVariable("GRID_SIZE_SPACE_TO_BATCH", 1)
#define BLOCK_SIZE_SPACE_TO_BATCH getEnvVariable("BLOCK_SIZE_SPACE_TO_BATCH",1)
#define SHARED_MEM_SIZE_SPACE_TO_BATCH getEnvVariable("SHARED_MEM_SIZE_SPACE_TO_BATCH", 1024)
#define GRID_SIZE_SPACE_TO_BATCH_ND getEnvVariable("GRID_SIZE_SPACE_TO_BATCH_ND", 1)
#define BLOCK_SIZE_SPACE_TO_BATCH_ND getEnvVariable("BLOCK_SIZE_SPACE_TO_BATCH_ND",1)
#define SHARED_MEM_SIZE_SPACE_TO_BATCH_ND getEnvVariable("SHARED_MEM_SIZE_SPACE_TO_BATCH_ND", 1024)
#define GRID_SIZE_SPACE_TO_DEPTH getEnvVariable("GRID_SIZE_SPACE_TO_DEPTH", 512)
#define BLOCK_SIZE_SPACE_TO_DEPTH getEnvVariable("BLOCK_SIZE_SPACE_TO_DEPTH",512)
#define SHARED_MEM_SIZE_SPACE_TO_DEPTH getEnvVariable("SHARED_MEM_SIZE_SPACE_TO_DEPTH", 1024)
#define GRID_SIZE_SCATTER getEnvVariable("GRID_SIZE_SCATTER", 512)
#define BLOCK_SIZE_SCATTER getEnvVariable("BLOCK_SIZE_SCATTER",512)
#define SHARED_MEM_SIZE_SCATTER getEnvVariable("SHARED_MEM_SIZE_SCATTER", 1024)
#define GRID_SIZE_SCATTER_CHECK_INDICES getEnvVariable("GRID_SIZE_SCATTER_CHECK_INDICES", 512)
#define BLOCK_SIZE_SCATTER_CHECK_INDICES getEnvVariable("BLOCK_SIZE_SCATTER_CHECK_INDICES",512)
#define SHARED_MEM_SIZE_SCATTER_CHECK_INDICES getEnvVariable("SHARED_MEM_SIZE_SCATTER_CHECK_INDICES", 1024)
#define GRID_SIZE_SCATTER_ND getEnvVariable("GRID_SIZE_SCATTER_ND", 512)
#define BLOCK_SIZE_SCATTER_ND getEnvVariable("BLOCK_SIZE_SCATTER_ND",512)
#define SHARED_MEM_SIZE_SCATTER_ND getEnvVariable("SHARED_MEM_SIZE_SCATTER_ND", 1024)
#define GRID_SIZE_SCATTER_SIMPLE getEnvVariable("GRID_SIZE_SCATTER_SIMPLE", 512)
#define BLOCK_SIZE_SCATTER_SIMPLE getEnvVariable("BLOCK_SIZE_SCATTER_SIMPLE",256)
#define SHARED_MEM_SIZE_SCATTER_SIMPLE getEnvVariable("SHARED_MEM_SIZE_SCATTER_SIMPLE", SD_MAX_NUM_THREADS)
#define GRID_SIZE_SCATTER_UPDATE getEnvVariable("GRID_SIZE_SCATTER_UPDATE", 256)
#define BLOCK_SIZE_SCATTER_UPDATE getEnvVariable("BLOCK_SIZE_SCATTER_UPDATE",256)
#define SHARED_MEM_SIZE_SCATTER_UPDATE getEnvVariable("SHARED_MEM_SIZE_SCATTER_UPDATE", 1024)
#define GRID_SIZE_SEGMENT_INDICES_VALIDATE getEnvVariable("GRID_SIZE_SEGMENT_INDICES_VALIDATE", 1)
#define BLOCK_SIZE_SEGMENT_INDICES_VALIDATE getEnvVariable("BLOCK_SIZE_SEGMENT_INDICES_VALIDATE",1)
#define SHARED_MEM_SIZE_SEGMENT_INDICES_VALIDATE getEnvVariable("SHARED_MEM_SIZE_SEGMENT_INDICES_VALIDATE", 128)
#define GRID_SIZE_SEGMENT getEnvVariable("GRID_SIZE_SEGMENT", 1)
#define BLOCK_SIZE_SEGMENT getEnvVariable("BLOCK_SIZE_SEGMENT",1)
#define SHARED_MEM_SIZE_SEGMENT getEnvVariable("SHARED_MEM_SIZE_SEGMENT", 128)
#define GRID_SIZE_SEGMENT_TAD getEnvVariable("GRID_SIZE_SEGMENT_TAD", 1)
#define BLOCK_SIZE_SEGMENT_TAD getEnvVariable("BLOCK_SIZE_SEGMENT_TAD",1)
#define SHARED_MEM_SIZE_SEGMENT_TAD getEnvVariable("SHARED_MEM_SIZE_SEGMENT_TAD", 128)
#define GRID_SIZE_SEGMENT_BP getEnvVariable("GRID_SIZE_SEGMENT_BP", 1)
#define BLOCK_SIZE_SEGMENT_BP getEnvVariable("BLOCK_SIZE_SEGMENT_BP",1)
#define SHARED_MEM_SIZE_SEGMENT_BP getEnvVariable("SHARED_MEM_SIZE_SEGMENT_BP", 128)
#define GRID_SIZE_SEGMENT_BP_TAD getEnvVariable("GRID_SIZE_SEGMENT_BP_TAD", 1)
#define BLOCK_SIZE_SEGMENT_BP_TAD getEnvVariable("BLOCK_SIZE_SEGMENT_BP_TAD",1)
#define SHARED_MEM_SIZE_SEGMENT_BP_TAD getEnvVariable("SHARED_MEM_SIZE_SEGMENT_BP_TAD", 128)
#define GRID_SIZE_SEGMENT_PROD_2_LINEAR getEnvVariable("GRID_SIZE_SEGMENT_PROD_2_LINEAR", 256)
#define BLOCK_SIZE_SEGMENT_PROD_2_LINEAR getEnvVariable("BLOCK_SIZE_SEGMENT_PROD_2_LINEAR",128)
#define SHARED_MEM_SIZE_SEGMENT_PROD_2_LINEAR getEnvVariable("SHARED_MEM_SIZE_SEGMENT_PROD_2_LINEAR", 128)
#define GRID_SIZE_SEGMENT_PROD_2_TAD getEnvVariable("GRID_SIZE_SEGMENT_PROD_2_TAD", 512)
#define BLOCK_SIZE_SEGMENT_PROD_2_TAD getEnvVariable("BLOCK_SIZE_SEGMENT_PROD_TAD",128)
#define SHARED_MEM_SIZE_SEGMENT_PROD_2_TAD getEnvVariable("SHARED_MEM_SIZE_SEGMENT_PROD_2_TAD", 2048)
#define GRID_SIZE_UNSORTEDSEGMENT_PROD_2 getEnvVariable("GRID_SIZE_UNSORTEDSEGMENT_PROD_2", 128)
#define BLOCK_SIZE_UNSORTEDSEGMENT_PROD_2 getEnvVariable("BLOCK_SIZE_UNSORTEDSEGMENT_PROD_2",256)
#define SHARED_MEM_SIZE_UNSORTEDSEGMENT_PROD_2 getEnvVariable("SHARED_MEM_SIZE_UNSORTEDSEGMENT_PROD_2", 256)
#define GRID_SIZE_SOLVE getEnvVariable("GRID_SIZE_SOLVE", 128)
#define BLOCK_SIZE_SOLVE getEnvVariable("BLOCK_SIZE_SOLVE",256)
#define SHARED_MEM_SIZE_SOLVE getEnvVariable("SHARED_MEM_SIZE_SOLVE", 256)
#define GRID_SIZE_SRU_BI getEnvVariable("GRID_SIZE_SRU_BI", 128)
#define BLOCK_SIZE_SRU_BI getEnvVariable("BLOCK_SIZE_SRU_BI",256)
#define SHARED_MEM_SIZE_SRU_BI getEnvVariable("SHARED_MEM_SIZE_SRU_BI", 256)
#define GRID_SIZE_STACK getEnvVariable("GRID_SIZE_STACK", 128)
#define BLOCK_SIZE_STACK getEnvVariable("BLOCK_SIZE_STACK",256)
#define SHARED_MEM_SIZE_STACK getEnvVariable("SHARED_MEM_SIZE_STACK", 256)
#define GRID_SIZE_TOP_K_MOVER getEnvVariable("GRID_SIZE_TOP_K_MOVER", 256)
#define BLOCK_SIZE_TOP_K_MOVER getEnvVariable("BLOCK_SIZE_TOP_K_MOVER",256)
#define SHARED_MEM_SIZE_TOP_K_MOVER getEnvVariable("SHARED_MEM_SIZE_TOP_K_MOVER", 1024)
#define GRID_SIZE_TOP_K_INDICES getEnvVariable("GRID_SIZE_TOP_K_INDICES", 256)
#define BLOCK_SIZE_TOP_K_INDICES getEnvVariable("BLOCK_SIZE_TOP_K_INDICES",256)
#define SHARED_MEM_SIZE_TOP_K_INDICES getEnvVariable("SHARED_MEM_SIZE_TOP_K_INDICES", 1024)
#define GRID_SIZE_INVERT_PERMUTE getEnvVariable("GRID_SIZE_INVERT_PERMUTE", 256)
#define BLOCK_SIZE_INVERT_PERMUTE getEnvVariable("BLOCK_SIZE_INVERT_PERMUTE",256)
#define SHARED_MEM_SIZE_INVERT_PERMUTE getEnvVariable("SHARED_MEM_SIZE_INVERT_PERMUTE", 1024)
#define GRID_SIZE_TRACE getEnvVariable("GRID_SIZE_TRACE", 256)
#define BLOCK_SIZE_TRACE getEnvVariable("BLOCK_SIZE_TRACE",256)
#define SHARED_MEM_SIZE_TRACE getEnvVariable("SHARED_MEM_SIZE_TRACE", 1024)
#define GRID_SIZE_TRIU getEnvVariable("GRID_SIZE_TRIU", 256)
#define BLOCK_SIZE_TRIU getEnvVariable("BLOCK_SIZE_TRIU",256)
#define SHARED_MEM_SIZE_TRIU getEnvVariable("SHARED_MEM_SIZE_TRIU", 1024)
#define GRID_SIZE_TILE getEnvVariable("GRID_SIZE_TILE", 256)
#define BLOCK_SIZE_TILE getEnvVariable("BLOCK_SIZE_TILE",256)
#define SHARED_MEM_SIZE_TILE getEnvVariable("SHARED_MEM_SIZE_TILE", 1024)
#define GRID_SIZE_TRIANGULAR_SOLVE getEnvVariable("GRID_SIZE_TRIANGULAR_SOLVE", 128)
#define BLOCK_SIZE_TRIANGULAR_SOLVE getEnvVariable("BLOCK_SIZE_TRIANGULAR_SOLVE",256)
#define SHARED_MEM_SIZE_TRIANGULAR_SOLVE getEnvVariable("SHARED_MEM_SIZE_TRIANGULAR_SOLVE", 256)
#define GRID_SIZE_UPDATER getEnvVariable("GRID_SIZE_UPDATER", 128)
#define BLOCK_SIZE_UPDATER getEnvVariable("BLOCK_SIZE_UPDATER",256)
#define SHARED_MEM_SIZE_UPDATER getEnvVariable("SHARED_MEM_SIZE_UPDATER", 256)
#define GRID_SIZE_ZETA getEnvVariable("GRID_SIZE_ZETA", 128)
#define BLOCK_SIZE_ZETA getEnvVariable("BLOCK_SIZE_ZETA",256)
#define SHARED_MEM_SIZE_ZETA getEnvVariable("SHARED_MEM_SIZE_ZETA", 1024)
#define GRID_SIZE_AVG_POOLING getEnvVariable("GRID_SIZE_AVG_POOLING", 512)
#define BLOCK_SIZE_AVG_POOLING getEnvVariable("BLOCK_SIZE_AVG_POOLING",512)
#define SHARED_MEM_SIZE_POOLING getEnvVariable("SHARED_MEM_SIZE_POOLING", 4192)
// Grid, block, and shared memory size definitions using environment variables
#define GRID_SIZE_MMUL getEnvVariable("GRID_SIZE_MMUL", 256)
#define BLOCK_SIZE_MMUL getEnvVariable("BLOCK_SIZE_MMUL", 512)
#define SHARED_MEM_SIZE_MMUL getEnvVariable("SHARED_MEM_SIZE_MMUL", 8192)
#define GRID_SIZE_IMAGE_RESIZE_NEIGHBOR getEnvVariable("GRID_SIZE_IMAGE_RESIZE_NEIGHBOR", 256)
#define BLOCK_SIZE_IMAGE_RESIZE_NEIGHBOR getEnvVariable("BLOCK_SIZE_IMAGE_RESIZE_NEIGHBOR", 512)
#define SHARED_MEM_SIZE_IMAGE_RESIZE_NEIGHBOR getEnvVariable("SHARED_MEM_SIZE_IMAGE_RESIZE_NEIGHBOR", 8192)
#define GRID_SIZE_SWAP_UNSAFE getEnvVariable("GRID_SIZE_SWAP_UNSAFE", 256)
#define BLOCK_SIZE_SWAP_UNSAFE getEnvVariable("BLOCK_SIZE_SWAP_UNSAFE", 512)
#define SHARED_MEM_SIZE_SWAP_UNSAFE getEnvVariable("SHARED_MEM_SIZE_SWAP_UNSAFE", 8192)
#define GRID_SIZE_DIGAMMA getEnvVariable("GRID_SIZE_DIGAMMA", 256)
#define BLOCK_SIZE_DIGAMMA getEnvVariable("BLOCK_SIZE_DIGAMMA", 512)
#define SHARED_MEM_SIZE_DIGAMMA getEnvVariable("SHARED_MEM_SIZE_DIGAMMA", 1024)
#define GRID_SIZE_FILL_TRI getEnvVariable("GRID_SIZE_FILL_TRI", 256)
#define BLOCK_SIZE_FILL_TRI getEnvVariable("BLOCK_SIZE_FILL_TRI", 512)
#define SHARED_MEM_SIZE_FILL_TRI getEnvVariable("SHARED_MEM_SIZE_FILL_TRI", 1024)
#define GRID_SIZE_IDENTITY getEnvVariable("GRID_SIZE_IDENTITY", 256)
#define BLOCK_SIZE_IDENTITY getEnvVariable("GRID_SIZE_IDENTITY", 512)
#define SHARED_MEM_SIZE_IDENTITY getEnvVariable("SHARED_MEM_SIZE_IDENTITY", 1024)
#define GRID_SIZE_DYNAMIC_STITCH_TAD getEnvVariable("GRID_SIZE_DYNAMIC_STITCH_TAD", 512)
#define BLOCK_SIZE_DYNAMIC_STITCH_TAD getEnvVariable("BLOCK_SIZE_DYNAMIC_STITCH_TAD", 512)
#define SHARED_MEM_SIZE_DYNAMIC_STITCH_TAD getEnvVariable("SHARED_MEM_SIZE_DYNAMIC_STITCH_TAD", 1024)
#define GRID_SIZE_DYNAMIC_PARTITION_TAD getEnvVariable("GRID_SIZE_DYNAMIC_PARTITION_TAD", 256)
#define BLOCK_SIZE_DYNAMIC_PARTITION_TAD getEnvVariable("BLOCK_SIZE_DYNAMIC_PARTITION_TAD", 256)
#define SHARED_MEM_SIZE_DYNAMIC_PARTITION_TAD getEnvVariable("SHARED_MEM_SIZE_DYNAMIC_PARTITION_TAD", 1024)
#define GRID_SIZE_SOLVE getEnvVariable("GRID_SIZE_SOLVE", 100)
#define BLOCK_SIZE_SOLVE getEnvVariable("BLOCK_SIZE_SOLVE", 1)
#define SHARED_MEM_SIZE_SOLVE getEnvVariable("SHARED_MEM_SIZE_SOLVE", 256)
#define GRID_SIZE_LUP getEnvVariable("GRID_SIZE_LUP", 128)
#define BLOCK_SIZE_LUP getEnvVariable("BLOCK_SIZE_LUP", 256)
#define SHARED_MEM_SIZE_LUP getEnvVariable("SHARED_MEM_SIZE_LUP", 1024)
#define GRID_SIZE_SOFTMAX getEnvVariable("GRID_SIZE_SOFTMAX", 128)
#define BLOCK_SIZE_SOFTMAX getEnvVariable("BLOCK_SIZE_SOFTMAX", 256)
#define SHARED_MEM_SIZE_SOFTMAX getEnvVariable("SHARED_MEM_SIZE_SOFTMAX", 1024)
dim3 getSoftmaxDims(int numTads);
dim3 getLupDims(int batchSize);
dim3 getDynamicPartitionDims(int numThreads,int yDTypeSize);
dim3 getIdentityLaunchDims(int len,int rank);
dim3 getRepeatLaunchDims(int len,int rank);
dim3 getFillTriLaunchDims(int len,int rank);
dim3 getGemVDims(int m);
dim3 getAddBiasDims(int len,int rank) ;
dim3 getLaunchDims(const std::string& key);
dim3 getCol2imLaunchParams(sd::NDArray im,sd::NDArray col);
dim3 getim2ColLaunchParams(sd::NDArray col);
dim3 getMMulDims(int length,int sizeofDataType);
dim3 getAccumDims(int xLength);
dim3 getReduceDims(int xLength);
dim3 getReduceAllDims(int xLength);
dim3 getSortFullDims(int xLength);
dim3 getSortTadLarge(int numberTads);
dim3 getSortTadDims(int numberTads);
dim3 getFillUpSegmentsDims(int numClasses,int length);
dim3 getSegmentSumDims(int numClasses,int length);
dim3 getSequenceMaskLaunchDims(int maxIndex,sd::NDArray input);
dim3 getPoolingDims(int length,int rank);
dim3 getCol2VolDims(int length,int rank);
dim3 getVol2ColDims(int length,int rank);
dim3 getUpsamplingDims(int length,int rank);
dim3 getHistogramDims(int length,int numBins);
dim3 getAdjustDims(int numTads);
dim3 getBatchNormDims(int length);
dim3 getCompareAndBitpackDims(int length);
dim3 getCompareElem(int length);
dim3 getConcat(int length);
dim3 getBetaInc(int maxIter,int length,int dataTypeSize);
dim3 getCross(int length,int rank,int lastSize);
dim3 getDilation(int outputLength,int weightRank,int outputRank);
dim3 getGatherLinear(int numSubArrs);
dim3 getGatherNd(int outputLength,int maxRank);
dim3 getHashCodeSplit(int length,int blockSize);
dim3 getHashCodeInternal( int numBlocks);
dim3 cropAndResize(int batchSize,int imageHeight,int imageWidth,int cropHeight,int cropWidth);
dim3 imageHelper(int numTads);
dim3 lrnDims(int tadLength,int numTads, int xDTypeSize,int zDTypeSize);
dim3 lupDims(int n);
dim3 lupDimsLow(int n);
dim3 matrixSetDiagDims(int length,int rank);
dim3 mergeDims(int length);
dim3 oneHotDims(int length,int rank,int shapeSize);
dim3 padDims(int length,int rank);
dim3 polygammaDims(int length);
dim3 prefixDims(int numTads,int sizeOfDataType);
dim3 randomShuffleFisherDims(int power,int inputDataTypeSize);
dim3 randomShuffleMergeDims(int j,int length);
dim3 batchToSpaceNdLaunch(int length,int rank);
dim3 spaceToBatchLaunch(int length,int rank);
dim3 spaceToBatchNdLaunch(int length,int rank);
dim3 scatterDims(int length,int rank);
dim3 scatterDimsCheckIndices(int length,int rank);
dim3 scatterNdDims(int length,int rank);
dim3 segmentValidateIndices(int length);
dim3 segmentDims(int numClasses,int length);
dim3 segmentTad(int size);
dim3 segmentBpDims(int gradOutLen,int inputLen);
dim3 segmentBpTad(int indicesLen,int inputLen);
dim3 sruBiDims(int len,int rank);
dim3 stackDims(int length);
dim3 topkDims(int numTads);
dim3 topKIndices(int scanWidth,int xDTypeSize,int yDTypeSize);
dim3 invertPermutationDims(int length);
dim3 traceDims(int length);
dim3 triuDims(int length,int rank);
dim3 tileDims(int length,int rank);
dim3 updaterDims(int length);
dim3 zetaDims(int length);
dim3 resizeNeighborDims(int batchSize,int height,int width);
dim3 clipDims(int length);
dim3 mirrorPadLinearDims(int length);
dim3 mirrorPadTad(int length,int rank);
dim3 digammaDims(int length);
#endif //LIBND4J_LAUNCHCONTEXT_H