Skip to content

Commit 9d274cf

Browse files
authored
99% compiler warnings changes (deeplearning4j#10179)
Clean up string and shape utils
1 parent 9f681e4 commit 9d274cf

32 files changed

+792
-1222
lines changed

libnd4j/include/array/ArrayOptions.hXX

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ SD_HOST void validateFlags(sd::LongType property, const sd::LongType flags[], si
288288
if (numFlagsSet > 1) {
289289
std::ostringstream errorMsg;
290290
errorMsg << "Multiple data types are set for the given property: ";
291-
for (int i = 0; i < numFlags; i++) {
291+
for (size_t i = 0; i < numFlags; i++) {
292292
if(flagIndices[i] == 1) {
293293
errorMsg << "Flag index " << i << " (flag value: " << flags[i] << "), ";
294294
}
@@ -316,6 +316,14 @@ SD_HOST void ArrayOptions::validateSingleDataType(sd::LongType property) {
316316
SD_HOST sd::DataType ArrayOptions::dataType(const sd::LongType *shapeInfo) {
317317
if(shapeInfo == nullptr)
318318
THROW_EXCEPTION("ArrayOptions::dataType(..) shapeInfo can not be null!");
319+
/*#if defined(SD_GCC_FUNCTRACE)
320+
Printer p;
321+
StackTrace st;
322+
st.load_here();
323+
FILE *fp = fopen("stacktrace-.txt", "a+");
324+
p.print(st,fp);
325+
fclose(fp);
326+
#endif*/
319327
auto extra = ArrayOptions::extra(shapeInfo);
320328
return ArrayOptions::dataTypeValue(extra);
321329
}

libnd4j/include/array/cpu/DataBuffer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
namespace sd {
3030
void DataBuffer::expand(const uint64_t size) {
31-
if (size > _lenInBytes) {
31+
if (static_cast<LongType>(size) > _lenInBytes) {
3232
// allocate new buffer
3333
int8_t* newBuffer = nullptr;
3434
ALLOCATE(newBuffer, _workspace, size, int8_t);
@@ -70,7 +70,7 @@ void DataBuffer::copyBufferFrom(const DataBuffer& other,
7070
sizeToCopyinBytes = otherBytes < thisBytes ? otherBytes : thisBytes;
7171
}
7272
if (sizeToCopyinBytes == 0) return;
73-
if(sizeToCopyinBytes > other._lenInBytes - offsetOther) {
73+
if(static_cast<LongType>(sizeToCopyinBytes) > other._lenInBytes - offsetOther) {
7474
std::string errorMessage;
7575
errorMessage = "DataBuffer::copyBufferFrom: size to copy is larger than source buffer ";
7676
errorMessage += std::to_string(sizeToCopyinBytes);
@@ -197,7 +197,7 @@ void _printHostBuffer(DataBuffer* buffer, long offset) {
197197

198198

199199
sd::LongType limit = len;
200-
if (limit == -1 || limit >= buffer->getNumElements()) {
200+
if (limit == -1 || limit >= static_cast<LongType>(buffer->getNumElements())) {
201201
limit = buffer->getNumElements();
202202
}
203203

@@ -214,7 +214,8 @@ void _printHostBuffer(DataBuffer* buffer, long offset) {
214214
for (sd::LongType e = baseOffset; e < limit; e++) {
215215
if (e > offset) printf(", ");
216216
if (dataType == sd::DataType::DOUBLE) {
217-
printf("%.15f", buff[e]);
217+
double val = static_cast<double>(buff[e]);
218+
printf("%.15f",val);
218219
} else {
219220
printf("%.15f", static_cast<float>(buff[e]));
220221
}

libnd4j/include/array/impl/ExtraArguments.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ void ExtraArguments::convertAndCopy(Pointer pointer, LongType offset) {
6767
#endif
6868

6969
if (!_fpArgs.empty()) {
70-
for (int e = offset; e < _fpArgs.size(); e++) {
70+
for (size_t e = offset; e < _fpArgs.size(); e++) {
7171
target[e] = static_cast<T>(_fpArgs[e]);
7272
}
7373
} else if (_intArgs.empty()) {
74-
for (int e = offset; e < _intArgs.size(); e++) {
74+
for (size_t e = offset; e < _intArgs.size(); e++) {
7575
target[e] = static_cast<T>(_intArgs[e]);
7676
}
7777
}

libnd4j/include/array/impl/ResultSet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ResultSet::ResultSet() {
2828
}
2929

3030
ResultSet::ResultSet(const graph::FlatResult* result) {
31-
for (int e = 0; e < result->variables()->size(); e++) {
31+
for (size_t e = 0; e < result->variables()->size(); e++) {
3232
auto var = result->variables()->Get(e);
3333

3434
NDArray* array;
@@ -37,7 +37,7 @@ ResultSet::ResultSet(const graph::FlatResult* result) {
3737
array = graph::FlatUtils::fromFlatArray(var->ndarray());
3838
} else if (var->shape() != nullptr) {
3939
std::vector<LongType> shapeInfo;
40-
for (int i = 0; i < var->shape()->size(); i++) {
40+
for (size_t i = 0; i < var->shape()->size(); i++) {
4141
shapeInfo.emplace_back(var->shape()->Get(i));
4242
}
4343

@@ -121,7 +121,7 @@ void ResultSet::delContent() {
121121
ResultSet::~ResultSet() { delContent(); }
122122

123123
void ResultSet::printIndexedBuffers() {
124-
for (int e = 0; e < _content.size(); e++) {
124+
for (size_t e = 0; e < _content.size(); e++) {
125125
auto array = _content.at(e);
126126
auto strVal = "Array e: " + std::to_string(e) + " is: ";
127127
array->printIndexedBuffer(strVal.c_str());

libnd4j/include/array/impl/ShapeDescriptor.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ LongType ShapeDescriptor::offset() {
7878
}
7979

8080
ShapeDescriptor::ShapeDescriptor(const DataType type, const char order, const LongType *shape, const LongType rank)
81-
: _dataType(type), _order(order), _rank(rank) {
81+
: _rank(rank), _order(order), _dataType(type) {
8282
int rank2 = rank < 1 ? 1 : rank;
8383
_shape_strides = new LongType[2 * rank2];
8484
this->ownsShapeStrides = true;
@@ -102,7 +102,7 @@ ShapeDescriptor::ShapeDescriptor(const DataType type, const char order, const Lo
102102
fillStrides();
103103

104104
#if defined(SD_GCC_FUNCTRACE)
105-
this-st.load_here();
105+
this->st.load_here();
106106
#endif
107107

108108

@@ -149,15 +149,15 @@ ShapeDescriptor::ShapeDescriptor(const DataType type, const char order, const Lo
149149
}
150150

151151
#if defined(SD_GCC_FUNCTRACE)
152-
this-st.load_here();
152+
this->st.load_here();
153153
#endif
154154
}
155155

156156
//////////////////////////////////////////////////////////////////////////
157157

158158

159159
ShapeDescriptor::ShapeDescriptor(const DataType type, const char order, const std::vector<LongType> &shape)
160-
: _dataType(type), _order(order) {
160+
: _order(order), _dataType(type) {
161161
if(!DataTypeUtils::validDataType(_dataType)) {
162162
THROW_EXCEPTION("Shape descriptor created with invalid data type");
163163
}
@@ -190,7 +190,7 @@ ShapeDescriptor::ShapeDescriptor(const DataType type, const char order, const st
190190
THROW_EXCEPTION("Shape descriptor created with invalid data type");
191191
}
192192
#if defined(SD_GCC_FUNCTRACE)
193-
this-st.load_here();
193+
this->st.load_here();
194194
#endif
195195
}
196196

@@ -204,12 +204,12 @@ ShapeDescriptor::ShapeDescriptor(const DataType type, const char order, const st
204204
THROW_EXCEPTION("Shape descriptor created with invalid data type");
205205
}
206206
#if defined(SD_GCC_FUNCTRACE)
207-
this-st.load_here();
207+
this->st.load_here();
208208
#endif
209209
}
210210

211211
ShapeDescriptor::ShapeDescriptor(const DataType type, const LongType length)
212-
: _dataType(type), _order('c'), _rank(1), _extraProperties(0) {
212+
: _rank(1), _order('c'), _dataType(type), _extraProperties(0) {
213213
_shape_strides = new LongType [2];
214214
_shape_strides[0] = length;
215215
_shape_strides[1] = 1; //{shape, stride}
@@ -218,7 +218,7 @@ ShapeDescriptor::ShapeDescriptor(const DataType type, const LongType length)
218218
}
219219

220220
#if defined(SD_GCC_FUNCTRACE)
221-
this-st.load_here();
221+
this->st.load_here();
222222
#endif
223223
}
224224

@@ -363,7 +363,7 @@ ShapeDescriptor::ShapeDescriptor(const LongType *shapeInfo, bool validateDataTyp
363363
}
364364

365365
#if defined(SD_GCC_FUNCTRACE)
366-
this-st.load_here();
366+
this->st.load_here();
367367
#endif
368368

369369
}
@@ -387,7 +387,7 @@ ShapeDescriptor::ShapeDescriptor(const LongType *shapeInfo, const DataType dtype
387387
}
388388

389389
#if defined(SD_GCC_FUNCTRACE)
390-
this-st.load_here();
390+
this->st.load_here();
391391
#endif
392392
}
393393

@@ -398,7 +398,7 @@ ShapeDescriptor::ShapeDescriptor(const LongType *shapeInfo, const LongType *dtyp
398398
}
399399

400400
#if defined(SD_GCC_FUNCTRACE)
401-
this-st.load_here();
401+
this->st.load_here();
402402
#endif
403403
}
404404

@@ -412,7 +412,7 @@ ShapeDescriptor::ShapeDescriptor(const LongType *shapeInfo, const LongType *dtyp
412412

413413

414414
#if defined(SD_GCC_FUNCTRACE)
415-
this-st.load_here();
415+
this->st.load_here();
416416
#endif
417417
}
418418

@@ -441,7 +441,7 @@ void ShapeDescriptor::print() const {
441441
printf("%lld", _shape_strides[i]);
442442
if (i < 2 * _rank - 1) printf(", ");
443443
}
444-
printf("], %c, %lld, %s, %lld\n", _order, DataTypeUtils::asString(_dataType).c_str(), _extraProperties);
444+
printf("], %c, %s, %lld\n", _order, DataTypeUtils::asString(_dataType).c_str(), _extraProperties);
445445
}
446446

447447
LongType ShapeDescriptor::allocLength() const {
@@ -549,7 +549,7 @@ DataType ShapeDescriptor::dataType() const {
549549
}
550550

551551
bool ShapeDescriptor::isEmpty() const { return (_extraProperties & ARRAY_EMPTY) == ARRAY_EMPTY; }
552-
bool ShapeDescriptor::isScalar() const { return !isEmpty() && rank() == 0 || rank() == 1 && arrLength() == 1; }
552+
bool ShapeDescriptor::isScalar() const { return (!isEmpty() && rank() == 0) || (rank() == 1 && arrLength() == 1); }
553553

554554
sd::LongType * ShapeDescriptor::shape_strides() { return _shape_strides; }
555555

@@ -568,21 +568,21 @@ ShapeDescriptor::ShapeDescriptor(const ShapeDescriptor &other) {
568568
this->ownsShapeStrides = false;
569569
_paddedAllocSize = other._paddedAllocSize;
570570
#if defined(SD_GCC_FUNCTRACE)
571-
this-st.load_here();
571+
this->st.load_here();
572572
#endif
573573
}
574574

575575
//////////////////////////////////////////////////////////////////////////
576576
ShapeDescriptor::ShapeDescriptor(const DataType type, const char order, const std::vector<LongType> &shape,
577577
const std::vector<LongType> &strides)
578-
: _dataType(type), _order(order) {
578+
: _order(order), _dataType(type) {
579579
_rank = shape.size();
580580
int rank2 = _rank < 1 ? 1 : _rank;
581581

582582
_shape_strides = new LongType [2 * rank2];
583583
this->ownsShapeStrides = true;
584584
#if defined(SD_GCC_FUNCTRACE)
585-
this-st.load_here();
585+
this->st.load_here();
586586
#endif
587587
auto _shape = _shape_strides;
588588
auto _strides = _shape_strides + rank2;
@@ -677,11 +677,11 @@ ShapeDescriptor * ShapeDescriptor::paddedBufferDescriptor(const DataType type,
677677
descriptor->_shape_strides = new LongType [2 * rank2];
678678
auto _shape = descriptor->_shape_strides;
679679
auto _strides = descriptor->_shape_strides + rank2;
680-
for (int i = 0; i < shape.size(); i++) {
680+
for (size_t i = 0; i < shape.size(); i++) {
681681
_shape[i] = shape[i];
682682
}
683683
// calculate strides with paddings
684-
int min_rank = descriptor->_rank > paddings.size() ? paddings.size() : rank2;
684+
int min_rank = static_cast<size_t>(descriptor->_rank) > paddings.size() ? paddings.size() : rank2;
685685
bool is_continous = true;
686686
if (order == 'c') {
687687
_strides[rank2 - 1] = 1L;
@@ -705,7 +705,7 @@ ShapeDescriptor * ShapeDescriptor::paddedBufferDescriptor(const DataType type,
705705
if (pad != 0) is_continous = false;
706706
}
707707
if (!is_continous && descriptor->_rank > 0) {
708-
LongType size_pad = paddings.size() >= descriptor->_rank ? paddings[descriptor->_rank - 1] : 0;
708+
LongType size_pad = paddings.size() >= static_cast<size_t>(descriptor->_rank) ? paddings[descriptor->_rank - 1] : 0;
709709
// alloc size should be supplied manually as we dont have place to store it
710710
descriptor->_paddedAllocSize = _strides[descriptor->_rank - 1] * (_shape[descriptor->_rank - 1] + size_pad);
711711
}

libnd4j/include/array/impl/ShapeList.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@
2525
namespace sd {
2626

2727

28-
ShapeList::ShapeList(const LongType* shape) {
28+
ShapeList::ShapeList(LongType* shape) {
2929
if (shape != nullptr) push_back(shape);
3030
}
3131

3232
ShapeList::~ShapeList() {
3333
if (_autoremovable) destroy();
3434
}
3535

36-
ShapeList::ShapeList(const std::vector<const LongType*>& shapes, bool isWorkspace)
36+
ShapeList::ShapeList(const std::vector< LongType*>& shapes, bool isWorkspace)
3737

3838
{
39-
for (int i = 0; i < shapes.size(); i++) {
39+
for (size_t i = 0; i < shapes.size(); i++) {
4040
push_back(shapes[i]);
4141
}
4242
_workspace = isWorkspace;
4343
}
4444

45-
ShapeList::ShapeList(const std::vector<const LongType*>& shapes) {
45+
ShapeList::ShapeList(const std::vector< LongType*>& shapes) {
4646
_shapes = shapes;
4747
}
4848

@@ -61,7 +61,7 @@ int ShapeList::size() const {
6161
return (int)_shapes.size();
6262
}
6363

64-
const LongType* ShapeList::at(int idx) {
64+
LongType* ShapeList::at(int idx) {
6565

6666
if (size() <= idx || idx < 0) {
6767
std::string errorMessage;
@@ -73,7 +73,7 @@ const LongType* ShapeList::at(int idx) {
7373
return _shapes[idx];
7474
}
7575

76-
void ShapeList::push_back(const LongType* shape) {
76+
void ShapeList::push_back( LongType* shape) {
7777
_shapes.push_back(shape);
7878
}
7979

libnd4j/include/array/impl/TadPack.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,32 @@ TadPack::TadPack(const ConstantShapeBuffer& shapes,
4141

4242
}
4343

44-
const LongType* TadPack::primaryShapeInfo() const {
44+
LongType* TadPack::primaryShapeInfo() {
4545
if(_tadShape.primary() == nullptr)
4646
THROW_EXCEPTION("TadPack::primaryShapeInfo: primary shape info is nullptr!");
4747
return _tadShape.primary();
4848
}
4949

50-
const LongType* TadPack::primaryOffsets() const {
50+
LongType* TadPack::primaryOffsets() {
5151
return _tadOffsets.primary();
5252
}
5353

54-
const LongType* TadPack::specialShapeInfo() const { return _tadShape.special(); }
54+
LongType* TadPack::specialShapeInfo() { return _tadShape.special(); }
5555

56-
const LongType* TadPack::specialOffsets() const { return _tadOffsets.special(); }
56+
LongType* TadPack::specialOffsets() { return _tadOffsets.special(); }
5757

5858
LongType TadPack::numberOfTads() const { return _numTads; }
5959

60-
const LongType* TadPack::platformShapeInfo() const {
60+
LongType* TadPack::platformShapeInfo() {
6161
return Environment::getInstance().isCPU() ? primaryShapeInfo() : specialShapeInfo();
6262
}
6363

64-
const LongType* TadPack::platformOffsets() const {
64+
LongType* TadPack::platformOffsets() {
6565
return Environment::getInstance().isCPU() ? primaryOffsets() : specialOffsets();
6666
}
6767

6868

69-
void TadPack::print(const char* msg) const {
69+
void TadPack::print(const char* msg) {
7070
printf("---------------------------\n");
7171
printf("%s: ", msg);
7272
printf("Offsets:\n");
@@ -93,5 +93,5 @@ void TadPack::print(const char* msg) const {
9393
printf("---------------------------\n");
9494
}
9595

96-
LongType TadPack::shapeInfoLength() const { return shape::shapeInfoLength(primaryShapeInfo()); }
96+
LongType TadPack::shapeInfoLength() { return shape::shapeInfoLength(primaryShapeInfo()); }
9797
} // namespace sd

libnd4j/include/execution/impl/ThreadPool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ ThreadPool::ThreadPool() {
104104

105105
ThreadPool::~ThreadPool() {
106106
// TODO: implement this one properly
107-
for (int e = 0; e < _queues.size(); e++) {
107+
for (size_t e = 0; e < _queues.size(); e++) {
108108
// stop each and every thread
109109

110110
// release queue and thread
@@ -149,7 +149,7 @@ Ticket *ThreadPool::tryAcquire(int numThreads) {
149149
t->acquiredThreads(numThreads);
150150

151151
// filling ticket with executable interfaces
152-
for (int e = 0, i = 0; e < _queues.size() && i < numThreads; e++) {
152+
for (size_t e = 0, i = 0; e < _queues.size() && i < static_cast<size_t>(numThreads); e++) {
153153
if (_interfaces[e]->available()) {
154154
t->attach(i++, _interfaces[e]);
155155
_interfaces[e]->markUnavailable();

0 commit comments

Comments
 (0)