Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined symbols, Migrate more ints -> sd::LongType #9963

Merged
merged 8 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions libnd4j/blas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Aurora")
# using GCC
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_TUNE} ${INFORMATIVE_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,$ORIGIN/")

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,$ORIGIN/,--no-undefined,-z")
# keep this, we need to ensure that all symbols are defined or it may fail on mac based platforms
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT(APPLE) AND NOT(WIN32))
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic -Wl,-export-dynamic")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -export-dynamic")
Expand Down
4 changes: 2 additions & 2 deletions libnd4j/include/array/NDArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,7 @@ class SD_LIB_EXPORT NDArray {
* returns true if all dimensions of array except one are unities, for example: [1,1,n,1], [n,1,1], [n], ...
* posOfNonUnityDim - one dimension with value > 1
*/
SD_INLINE bool isCommonVector(int &posOfNonUnityDim) const;
SD_INLINE bool isCommonVector(LongType &posOfNonUnityDim) const;

/**
* returns true if array is scalar
Expand Down Expand Up @@ -1735,7 +1735,7 @@ bool NDArray::isRowVector() const {
}

//////////////////////////////////////////////////////////////////////////
bool NDArray::isCommonVector(int &posOfNonUnityDim) const {
bool NDArray::isCommonVector(LongType &posOfNonUnityDim) const {
return shape::isCommonVector(_shapeInfo, posOfNonUnityDim);
}

Expand Down
10 changes: 5 additions & 5 deletions libnd4j/include/array/NDArray.hXX
Original file line number Diff line number Diff line change
Expand Up @@ -5081,8 +5081,8 @@ namespace sd {
bool keepUnitiesInShape) const {
std::vector<sd::LongType> idxRanges(2 * rankOf());

const auto rank = rankOf();
const auto subArrRank = static_cast<int>(dimsToExclude.size());
const sd::LongType rank = rankOf();
const sd::LongType subArrRank = static_cast<sd::LongType>(dimsToExclude.size());

if (subArrRank > rank)
throw std::invalid_argument(
Expand All @@ -5095,7 +5095,7 @@ namespace sd {

if (subArrRank != 0) {
std::vector<sd::LongType> shapeOfSubArr(subArrRank), indexes(subArrRank);
for (int i = 0; i < subArrRank; ++i) shapeOfSubArr[i] = sizeAt(dimsToExclude[i]);
for (sd::LongType i = 0; i < subArrRank; ++i) shapeOfSubArr[i] = sizeAt(dimsToExclude[i]);

shape::index2coords(subArrIdx, subArrRank, shapeOfSubArr.data(), indexes.data());

Expand All @@ -5114,8 +5114,8 @@ namespace sd {
sd::LongType *&subArrOffsets, bool keepUnitiesInShape) const {
if (isEmpty()) throw std::invalid_argument("NDArray::getSubArrShapeAndOffsets: array is empty !");

const int rank = rankOf();
const int subArrRank = (rank == dimsToExclude.size() || keepUnitiesInShape) ? rank : rank - dimsToExclude.size();
const sd::LongType rank = rankOf();
const sd::LongType subArrRank = (rank == dimsToExclude.size() || keepUnitiesInShape) ? rank : rank - dimsToExclude.size();
const sd::LongType numOfSubArrs = ShapeUtils::getNumOfSubArrs(_shapeInfo, dimsToExclude);

// allocate memory
Expand Down
22 changes: 11 additions & 11 deletions libnd4j/include/array/cpu/NDArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ void NDArray::fillAsTriangular(const float val, int lower, int upper, NDArray& t
//track input vector coordinates, only used in specific cases
sd::LongType vectorCoord[1];
vectorCoord[0] = 0;
int targetRank = target.rankOf();
int thisRank = this->rankOf();
sd::LongType targetRank = target.rankOf();
sd::LongType thisRank = this->rankOf();
bool notVectorScalar = targetRank == 2 && thisRank == 2;
bool thisNotVectorScalar = !shape::isScalar(this->shapeInfo()) && !shape::isVector(this->shapeInfo());
bool targetNotVectorScalar = !shape::isScalar(target.shapeInfo()) && !shape::isVector(target.shapeInfo());
for (auto i = start; i < stop; i++) {
for (sd::LongType i = start; i < stop; i++) {
shape::index2coordsCPU(start, i, target.shapeInfo(), coords);
sd::LongType row = targetNotVectorScalar ? coords[zRank - 2] : 0;
sd::LongType col = targetNotVectorScalar ? coords[zRank - 1]: 1;
Expand Down Expand Up @@ -182,14 +182,14 @@ static void templatedSwap(void* xBuffer, void* yBuffer, const sd::LongType* xSha

auto func = PRAGMA_THREADS_FOR {
if (isSameOrders && xEws > 0 && yEws > 0) {
for (auto i = start; i < stop; i++) sd::math::sd_swap(x[i * xEws], y[i * yEws]);
for (sd::LongType i = start; i < stop; i++) sd::math::sd_swap(x[i * xEws], y[i * yEws]);
} else if (shape::haveSameShapeAndStrides(xShapeInfo, yShapeInfo)) {
for (auto i = start; i < stop; i++) {
for (sd::LongType i = start; i < stop; i++) {
const auto ind = shape::getIndexOffset(i, xShapeInfo);
sd::math::sd_swap(x[ind], y[ind]);
}
} else {
for (auto i = start; i < stop; i++) {
for (sd::LongType i = start; i < stop; i++) {
const auto xInd = shape::getIndexOffset(i, xShapeInfo);
const auto yInd = shape::getIndexOffset(i, yShapeInfo);
sd::math::sd_swap(x[xInd], y[yInd]);
Expand Down Expand Up @@ -481,26 +481,26 @@ void NDArray::tile(NDArray& target) const {

////////////////////////////////////////////////////////////////////////
template <typename X, typename Z>
static void repeat_(const NDArray& input, NDArray& output, const std::vector<LongType>& repeats, const int axis) {
static void repeat_(const NDArray& input, NDArray& output, const std::vector<LongType>& repeats, const LongType axis) {
const X* x = input.bufferAsT<X>();
Z* z = output.bufferAsT<Z>();

const int rank = input.rankOf(); // xRank = zRank
const int zLen = output.lengthOf(); // xLen <= zLen
const sd::LongType rank = input.rankOf(); // xRank = zRank
const sd::LongType zLen = output.lengthOf(); // xLen <= zLen
const sd::Unsigned repSize = repeats.size();

// loop through input array
auto func = PRAGMA_THREADS_FOR {
sd::LongType coords[SD_MAX_RANK], temp;

for (auto i = start; i < stop; i++) {
for (sd::LongType i = start; i < stop; i++) {
shape::index2coordsCPU(start, i, output.shapeInfo(), coords);
const auto zOffset = shape::getOffset(output.shapeInfo(), coords);

temp = coords[axis];

if (repSize > 1) {
for (sd::Unsigned j = 0; j < repSize; ++j) {
for (sd::LongType j = 0; j < repSize; ++j) {
coords[axis] -= repeats[j];
if (coords[axis] < 0) {
coords[axis] = j;
Expand Down
2 changes: 1 addition & 1 deletion libnd4j/include/execution/LaunchContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SD_LIB_EXPORT LaunchContext {

void* getReductionPointer() const;
void* getScalarPointer() const;
int* getAllocationPointer() const;
LongType* getAllocationPointer() const;
void* getCublasHandle() const;
void* getCusolverHandle() const;
void* getCuDnnHandle() const;
Expand Down
2 changes: 1 addition & 1 deletion libnd4j/include/execution/cuda/LaunchContext.cu
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void* LaunchContext::getReductionPointer() const { return contextBuffers.reducti

void* LaunchContext::getScalarPointer() const { return contextBuffers.scalarBuffer(); };

int* LaunchContext::getAllocationPointer() const { return reinterpret_cast<int*>(contextBuffers.allocationBuffer()); };
LongType* LaunchContext::getAllocationPointer() const { return reinterpret_cast<sd::LongType *>(contextBuffers.allocationBuffer()); };

void* LaunchContext::getCublasHandle() const { return CublasHelper::getInstance().handle(); };

Expand Down
3 changes: 2 additions & 1 deletion libnd4j/include/helpers/ConstantShapeHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class SD_LIB_EXPORT ConstantShapeHelper {
ConstantShapeBuffer* createShapeInfoWithNoUnitiesForReduce(const sd::LongType* maxShapeInfo,
const std::vector<sd::LongType>& dimsWithUnities,
sd::memory::Workspace* workspace = nullptr);
ConstantShapeBuffer* createSubArrShapeInfo(const sd::LongType* inShapeInfo, const LongType* dims, const int dimsSize,
ConstantShapeBuffer* createSubArrShapeInfo(const sd::LongType* inShapeInfo, const LongType* dims,
const LongType dimsSize,
sd::memory::Workspace* workspace = nullptr);

const sd::LongType* emptyShapeInfo(sd::DataType dataType);
Expand Down
10 changes: 5 additions & 5 deletions libnd4j/include/helpers/LoopKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ LoopKind::Kind LoopKind::deduceKindOfLoopXZ(const sd::LongType* xShapeInfo, cons
const char xOrder = shape::order(xShapeInfo);
const char zOrder = shape::order(zShapeInfo);

int temp;
sd::LongType temp;
const bool xVectorOrC = shape::isCommonVector(xShapeInfo, temp) || xOrder == 'c';
const bool zVectorOrC = shape::isCommonVector(zShapeInfo, temp) || zOrder == 'c';
const bool shapesSame = shape::shapeEquals(xShapeInfo, zShapeInfo);
Expand Down Expand Up @@ -161,7 +161,7 @@ LoopKind::Kind LoopKind::deduceKindOfLoopXYZ(const sd::LongType* xShapeInfo, con
const char yOrder = shape::order(yShapeInfo);
const char zOrder = shape::order(zShapeInfo);

int temp;
sd::LongType temp;
const bool xVectorOrC = shape::isCommonVector(xShapeInfo, temp) || xOrder == 'c';
const bool yVectorOrC = shape::isCommonVector(yShapeInfo, temp) || yOrder == 'c';
const bool zVectorOrC = shape::isCommonVector(zShapeInfo, temp) || zOrder == 'c';
Expand Down Expand Up @@ -200,10 +200,10 @@ LoopKind::Kind LoopKind::deduceKindOfLoopTadXZ(const sd::LongType* xShapeInfo, c

const bool allC = (tOrder == zOrder && zOrder == 'c');

int temp;
sd::LongType temp;
const bool tVectorOrC = shape::isCommonVector(tadShapeInfo, temp) || tOrder == 'c';
const bool zVectorOrC = shape::isCommonVector(zShapeInfo, temp) || zOrder == 'c';
;


if (shape::length(tadShapeInfo) * shape::length(zShapeInfo) <= Environment::getInstance().elementwiseThreshold() &&
xEws == 1 && xOrder == 'c' && xRank == 2 && tEws > 1 && zEws == 1 && (allC || (tVectorOrC && zVectorOrC)))
Expand Down Expand Up @@ -235,7 +235,7 @@ LoopKind::Kind LoopKind::deduceKindOfLoopTadXYZ(const sd::LongType* xTadShapeInf
const char yTadOrder = shape::order(xTadShapeInfo);
const char zOrder = shape::order(zShapeInfo);

int position;
sd::LongType position;
const bool xTadVectorOrC = shape::isCommonVector(xTadShapeInfo, position) || xTadOrder == 'c';
const bool yTadVectorOrC = shape::isCommonVector(yTadShapeInfo, position) || yTadOrder == 'c';
const bool zVectorOrC = shape::isCommonVector(zShapeInfo, position) || zOrder == 'c';
Expand Down
5 changes: 1 addition & 4 deletions libnd4j/include/helpers/TAD.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ SD_INLINE sd::LongType *TAD::tad2Sub(sd::LongType index, void *ptrManager) {
sd::LongType len = 1;
// left over index cursor for initializing elements
int leftOverIndex = 0;
for (int i = 0; i < rank; i++) {
for (sd::LongType i = 0; i < rank; i++) {
// look for dimensions NOT found in dimension length (basically compute shape - dimension (set difference)
bool found = false;
for (int j = 0; j < originalDimensionLength; j++) {
Expand All @@ -562,9 +562,6 @@ SD_INLINE sd::LongType *TAD::tad2Sub(sd::LongType index, void *ptrManager) {
}

// sub for indices
/* int *sub = new int[leftOverIndexLen];
shape::ind2subOrder(tadShape,index,len,sub);
*/
shape::index2coords(index, leftOverIndexLen, tadShape, sub);

for (int i = 0; i < leftOverIndexLen; i++) {
Expand Down
1 change: 0 additions & 1 deletion libnd4j/include/helpers/benchmark/ParametersBatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class ParametersBatch {
xShape[e] = values.size();
}

// sd_printf("Total Iterations: %i\n", totalIterations);

for (int i = 0; i < totalIterations; i++) {
if (xRank > 0) shape::index2coords(i, xRank, xShape, xCoords);
Expand Down
4 changes: 2 additions & 2 deletions libnd4j/include/helpers/cpu/ConstantShapeHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ ConstantShapeBuffer* ConstantShapeHelper::createShapeInfoWithNoUnitiesForReduce(
ALLOCATE(newShapeInfo, workspace, shape::shapeInfoLength(shape::rank(inShapeInfo) - dimsWithUnities.size()),
sd::LongType);

int temp;
sd::LongType temp;
if (dimsWithUnities.size() == 1 && shape::isCommonVector(inShapeInfo, temp) && temp == dimsWithUnities[0]) {
auto dims = ShapeUtils::evalDimsToExclude(shape::rank(inShapeInfo), {temp});
shape::excludeUnitiesFromShapeInfo(inShapeInfo, dims.data(), dims.size(), newShapeInfo);
Expand All @@ -227,7 +227,7 @@ ConstantShapeBuffer* ConstantShapeHelper::createShapeInfoWithNoUnitiesForReduce(

////////////////////////////////////////////////////////////////////////
ConstantShapeBuffer* ConstantShapeHelper::createSubArrShapeInfo(const sd::LongType* inShapeInfo, const LongType* dims,
const int dimsSize, sd::memory::Workspace* workspace) {
const sd::LongType dimsSize, sd::memory::Workspace* workspace) {
sd::LongType* newShapeInfo = ShapeBuilders::createSubArrShapeInfo(inShapeInfo, dims, dimsSize, workspace);

ShapeDescriptor *descriptor = new ShapeDescriptor(newShapeInfo);
Expand Down