2021-02-01 13:31:45 +01:00
|
|
|
/* ******************************************************************************
|
|
|
|
*
|
2020-01-24 08:11:09 +01: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.
|
2020-01-24 08:11:09 +01: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
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
//
|
|
|
|
// @author raver119@gmail.com
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "testlayers.h"
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <array/NDArray.h>
|
|
|
|
#include <graph/Context.h>
|
|
|
|
#include <graph/Node.h>
|
2020-01-24 08:11:09 +01:00
|
|
|
#include <graph/Variable.h>
|
|
|
|
#include <graph/VariableSpace.h>
|
|
|
|
#include <ops/declarable/CustomOperations.h>
|
|
|
|
#include <ops/declarable/helpers/convolutions.h>
|
|
|
|
#include <ops/declarable/helpers/col2im.h>
|
|
|
|
#include <helpers/RandomLauncher.h>
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
using namespace sd;
|
|
|
|
using namespace sd::graph;
|
|
|
|
using namespace sd::memory;
|
2020-01-24 08:11:09 +01:00
|
|
|
|
|
|
|
class DataBufferTests : public testing::Test {
|
|
|
|
public:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DataBufferTests, test_alloc_limit_1) {
|
2020-06-06 14:26:55 +02:00
|
|
|
if (!Environment::getInstance().isCPU())
|
2020-01-24 08:11:09 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
auto deviceId = AffinityManager::currentDeviceId();
|
2020-06-06 14:26:55 +02:00
|
|
|
auto odLimit = MemoryCounter::getInstance().deviceLimit(deviceId);
|
|
|
|
auto ogLimit = MemoryCounter::getInstance().groupLimit(MemoryType::HOST);
|
|
|
|
auto odUse = MemoryCounter::getInstance().allocatedDevice(deviceId);
|
|
|
|
auto ogUse = MemoryCounter::getInstance().allocatedGroup(MemoryType::HOST);
|
2020-01-24 08:11:09 +01:00
|
|
|
|
2020-01-24 13:26:46 +01:00
|
|
|
auto limitSize = odUse + (150 * 1024 * 1024);
|
2020-01-24 08:11:09 +01:00
|
|
|
auto allocSize = 100000000;
|
|
|
|
|
2020-06-06 14:26:55 +02:00
|
|
|
MemoryCounter::getInstance().setDeviceLimit(deviceId, odLimit + limitSize);
|
|
|
|
MemoryCounter::getInstance().setGroupLimit(MemoryType::HOST, odLimit + limitSize);
|
2020-01-24 08:11:09 +01:00
|
|
|
|
|
|
|
DataBuffer buffer(allocSize, DataType::INT32);
|
|
|
|
|
|
|
|
// separately testing per-device limits and group limits
|
2020-06-06 14:26:55 +02:00
|
|
|
ASSERT_EQ(odUse + allocSize, MemoryCounter::getInstance().allocatedDevice(deviceId));
|
|
|
|
ASSERT_EQ(ogUse + allocSize, MemoryCounter::getInstance().allocatedGroup(MemoryType::HOST));
|
2020-01-24 08:11:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
// setting smaller limits, to make sure next allocation fails with OOM exception
|
2020-06-06 14:26:55 +02:00
|
|
|
MemoryCounter::getInstance().setDeviceLimit(deviceId, allocSize - 100);
|
|
|
|
MemoryCounter::getInstance().setGroupLimit(MemoryType::HOST, allocSize - 100);
|
2020-01-24 08:11:09 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
DataBuffer bufferFailed(allocSize, DataType::INT32);
|
|
|
|
ASSERT_TRUE(false);
|
|
|
|
} catch (allocation_exception &e) {
|
|
|
|
// we expect exception here
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore original limits, so subsequent tests do not fail
|
2020-06-06 14:26:55 +02:00
|
|
|
MemoryCounter::getInstance().setDeviceLimit(deviceId, odLimit);
|
|
|
|
MemoryCounter::getInstance().setGroupLimit(MemoryType::HOST, odLimit);
|
2020-01-24 08:11:09 +01:00
|
|
|
}
|