2019-06-06 14:21:15 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2015-2018 Skymind, Inc.
|
|
|
|
*
|
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the Apache License, Version 2.0 which is available at
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
//
|
|
|
|
// @author raver119@gmail.com
|
|
|
|
//
|
|
|
|
|
2020-06-06 14:26:55 +02:00
|
|
|
#include <array/ConstantDataBuffer.h>
|
|
|
|
#include <array/DataTypeUtils.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2020-06-06 14:26:55 +02:00
|
|
|
ConstantDataBuffer::ConstantDataBuffer(
|
|
|
|
const std::shared_ptr<PointerWrapper>& primary,
|
|
|
|
uint64_t numEelements,
|
|
|
|
DataType dtype) : ConstantDataBuffer(primary, {}, numEelements, dtype) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstantDataBuffer::ConstantDataBuffer(
|
|
|
|
const std::shared_ptr<PointerWrapper>& primary,
|
|
|
|
const std::shared_ptr<PointerWrapper>& special,
|
|
|
|
uint64_t numEelements,
|
|
|
|
DataType dtype) : _primaryBuffer(primary), _specialBuffer(special), _length(numEelements) {
|
|
|
|
_sizeOf = DataTypeUtils::sizeOf(dtype);
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-06-06 14:26:55 +02:00
|
|
|
void* ConstantDataBuffer::primary() const {
|
|
|
|
return _primaryBuffer->pointer();
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-06-06 14:26:55 +02:00
|
|
|
void* ConstantDataBuffer::special() const {
|
|
|
|
return _specialBuffer ? _specialBuffer->pointer() : nullptr;
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
|
|
|
|
2020-06-06 14:26:55 +02:00
|
|
|
uint8_t ConstantDataBuffer::sizeOf() const {
|
2019-06-06 14:21:15 +02:00
|
|
|
return _sizeOf;
|
|
|
|
}
|
|
|
|
|
2020-06-06 14:26:55 +02:00
|
|
|
uint64_t ConstantDataBuffer::length() const {
|
2019-06-06 14:21:15 +02:00
|
|
|
return _length;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstantDataBuffer::ConstantDataBuffer(const ConstantDataBuffer &other) {
|
|
|
|
_primaryBuffer = other._primaryBuffer;
|
|
|
|
_specialBuffer = other._specialBuffer;
|
|
|
|
_length = other._length;
|
|
|
|
_sizeOf = other._sizeOf;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2020-06-06 14:26:55 +02:00
|
|
|
T* ConstantDataBuffer::primaryAsT() const {
|
|
|
|
return reinterpret_cast<T*>(_primaryBuffer->pointer());
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
2020-06-06 14:26:55 +02:00
|
|
|
template ND4J_EXPORT float* ConstantDataBuffer::primaryAsT<float>() const;
|
|
|
|
template ND4J_EXPORT double* ConstantDataBuffer::primaryAsT<double>() const;
|
|
|
|
template ND4J_EXPORT int* ConstantDataBuffer::primaryAsT<int>() const;
|
|
|
|
template ND4J_EXPORT Nd4jLong* ConstantDataBuffer::primaryAsT<Nd4jLong>() const;
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
template <typename T>
|
2020-06-06 14:26:55 +02:00
|
|
|
T* ConstantDataBuffer::specialAsT() const {
|
|
|
|
return reinterpret_cast<T*>(special());
|
2019-06-06 14:21:15 +02:00
|
|
|
}
|
2020-06-06 14:26:55 +02:00
|
|
|
template ND4J_EXPORT float* ConstantDataBuffer::specialAsT<float>() const;
|
|
|
|
template ND4J_EXPORT double* ConstantDataBuffer::specialAsT<double>() const;
|
|
|
|
template ND4J_EXPORT int* ConstantDataBuffer::specialAsT<int>() const;
|
|
|
|
template ND4J_EXPORT Nd4jLong* ConstantDataBuffer::specialAsT<Nd4jLong>() const;
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
}
|