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

[#399][Sys] Remove sysctl usage #432

Merged
merged 2 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,39 +87,39 @@ jobs:
- uses: actions/checkout@v2

- name: Compiler info
run: make -j 16 info
if: ${{ !matrix.useCMake }}
run: make -j 16 info

- name: CMake build
if: ${{ matrix.useCMake }}
run: |
cmake -E make_directory ${{runner.workspace}}/occa/build
cd ${{runner.workspace}}/occa/build
cmake -DENABLE_TESTS=On -DENABLE_EXAMPLES=On ${{runner.workspace}}/occa
make -j 16
if: ${{ matrix.useCMake }}

- name: Compile library
run: make -j 16
if: ${{ !matrix.useCMake }}
run: make -j 16

- name: Compile tests
run: make -j 16 tests
if: ${{ !matrix.useCMake }}
run: make -j 16 tests

- name: Run unit tests
run: ./tests/run_tests
if: ${{ !matrix.useCMake }}
run: ./tests/run_tests

- name: Run examples
run: ./tests/run_examples
if: ${{ !matrix.useCMake }}
run: ./tests/run_examples

- name: Run CTests
if: ${{ matrix.useCMake }}
run: |
cd ${{runner.workspace}}/occa/build
make test
if: ${{ matrix.useCMake }}
CTEST_OUTPUT_ON_FAILURE=1 make test

- name: Upload code coverage
run: bash <(curl --no-buffer -s https://codecov.io/bash) -x "${GCOV}"
if: ${{ matrix.OCCA_COVERAGE }}
run: bash <(curl --no-buffer -s https://codecov.io/bash) -x "${GCOV}"
1 change: 1 addition & 0 deletions include/occa/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OCCA_IO_HEADER

#include <occa/io/cache.hpp>
#include <occa/io/enums.hpp>
#include <occa/io/fileOpener.hpp>
#include <occa/io/lock.hpp>
#include <occa/io/utils.hpp>
Expand Down
14 changes: 14 additions & 0 deletions include/occa/io/enums.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef OCCA_IO_ENUMS_HEADER
#define OCCA_IO_ENUMS_HEADER

namespace occa {
namespace enums {
enum FileType {
FILE_TYPE_TEXT,
FILE_TYPE_BINARY,
FILE_TYPE_PSEUDO
};
}
}

#endif
5 changes: 3 additions & 2 deletions include/occa/io/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iostream>

#include <occa/types.hpp>
#include <occa/io/enums.hpp>

namespace occa {
// Kernel Caching
Expand Down Expand Up @@ -69,10 +70,10 @@ namespace occa {

char* c_read(const std::string &filename,
size_t *chars = NULL,
const bool readingBinary = false);
const enums::FileType fileType = enums::FILE_TYPE_TEXT);

std::string read(const std::string &filename,
const bool readingBinary = false);
const enums::FileType fileType = enums::FILE_TYPE_TEXT);

void write(const std::string &filename,
const std::string &content);
Expand Down
2 changes: 1 addition & 1 deletion include/occa/lang/primitive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include <occa/defines.hpp>
#include <occa/io/output.hpp>
#include <occa/tools/logging.hpp>
#include <occa/tools/string.hpp>
#include <occa/tools/sys.hpp>

namespace occa {
//---[ Primitive Type ]---------------
Expand Down
1 change: 1 addition & 0 deletions include/occa/tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <occa/tools/exception.hpp>
#include <occa/tools/gc.hpp>
#include <occa/tools/hash.hpp>
#include <occa/tools/enums.hpp>
#include <occa/tools/json.hpp>
#include <occa/tools/lex.hpp>
#include <occa/tools/misc.hpp>
Expand Down
21 changes: 21 additions & 0 deletions include/occa/tools/enums.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef OCCA_TOOLS_ENUMS_HEADER
#define OCCA_TOOLS_ENUMS_HEADER

namespace occa {
namespace sys {
namespace language {
static const int notFound = 0;
static const int CPP = 1;
static const int C = 2;
}

enum class CacheLevel {
L1D,
L1I,
L2,
L3
};
}
}

#endif
43 changes: 43 additions & 0 deletions include/occa/tools/logging.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef OCCA_TOOLS_LOGGING_HEADER
#define OCCA_TOOLS_LOGGING_HEADER

#include <iostream>

namespace occa {
namespace io {
class output;
}

void _message(const std::string &header,
const bool exitInFailure,
const std::string &filename,
const std::string &function,
const int line,
const std::string &message);

void warn(const std::string &filename,
const std::string &function,
const int line,
const std::string &message);

void error(const std::string &filename,
const std::string &function,
const int line,
const std::string &message);

void printWarning(io::output &out,
const std::string &message,
const std::string &code = "");

void printWarning(const std::string &message,
const std::string &code = "");

void printError(io::output &out,
const std::string &message,
const std::string &code = "");

void printError(const std::string &message,
const std::string &code = "");
}

#endif
24 changes: 24 additions & 0 deletions include/occa/tools/misc.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
#ifndef OCCA_TOOLS_MISC_HEADER
#define OCCA_TOOLS_MISC_HEADER

#include <initializer_list>

#include <occa/defines.hpp>
#include <occa/types.hpp>

namespace occa {
udim_t ptrDiff(void *start, void *end);

template <class TM>
TM min(std::initializer_list<TM> values) {
TM minValue = *values.begin();
for (const TM &value : values) {
if (value < minValue) {
minValue = value;
}
}
return minValue;
}

template <class TM>
TM max(std::initializer_list<TM> values) {
TM maxValue = *values.begin();
for (const TM &value : values) {
if (maxValue < value) {
maxValue = value;
}
}
return maxValue;
}

template <class TM>
void ignoreResult(const TM &t) {
(void) t;
Expand Down
64 changes: 40 additions & 24 deletions include/occa/tools/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <occa/types.hpp>

namespace occa {
//---[ Helper Methods ]---------------
std::string strip(const std::string &str);

std::string stripLeft(const std::string &str);
Expand All @@ -35,6 +36,9 @@ namespace occa {
const char delimeter,
const char escapeChar = 0);

std::string join(const strVector &vec,
const std::string &delimiter);

inline char uppercase(const char c) {
if (('a' <= c) && (c <= 'z')) {
return ((c + 'A') - 'a');
Expand Down Expand Up @@ -63,6 +67,30 @@ namespace occa {
return lowercase(s.c_str(), s.size());
}

inline bool startsWith(const std::string &s,
const std::string &match) {
const int matchChars = (int) match.size();
return ((matchChars <= (int) s.size()) &&
(!strncmp(s.c_str(), match.c_str(), matchChars)));
}

inline bool endsWith(const std::string &s,
const std::string &match) {
const int sChars = (int) s.size();
const int matchChars = (int) match.size();
return ((matchChars <= sChars) &&
(!strncmp(s.c_str() + (sChars - matchChars),
match.c_str(),
matchChars)));
}

inline bool contains(const std::string &s,
const std::string &match) {
return s.find(match) != std::string::npos;
}
//====================================

//---[ Stringify ]--------------------
template <class TM>
std::string toString(const TM &t) {
std::stringstream ss;
Expand Down Expand Up @@ -134,33 +162,19 @@ namespace occa {
}
return ret;
}
//====================================

inline bool startsWith(const std::string &s,
const std::string &match) {
const int matchChars = (int) match.size();
return ((matchChars <= (int) s.size()) &&
(!strncmp(s.c_str(), match.c_str(), matchChars)));
}
//---[ Formatters ]-------------------
udim_t parseInt(const std::string &str);
udim_t parseInt(const char *c);

inline bool endsWith(const std::string &s,
const std::string &match) {
const int sChars = (int) s.size();
const int matchChars = (int) match.size();
return ((matchChars <= sChars) &&
(!strncmp(s.c_str() + (sChars - matchChars),
match.c_str(),
matchChars)));
}

udim_t atoi(const char *c);
udim_t atoiBase2(const char *c);
udim_t atoi(const std::string &str);
udim_t parseBinary(const char *c);

double atof(const char *c);
double atof(const std::string &str);
double parseFloat(const std::string &str);
double parseFloat(const char *c);

double atod(const char *c);
double atod(const std::string &str);
double parseDouble(const std::string &str);
double parseDouble(const char *c);

inline char toHexChar(const char c) {
if (c < 16) {
Expand Down Expand Up @@ -247,10 +261,12 @@ namespace occa {
}

std::string stringifyBytes(udim_t bytes);

void stringifyBytesFraction(std::stringstream &ss,
uint64_t fraction);

std::string stringifyFrequency(udim_t frequency);
//====================================

//---[ Color Strings ]----------------
namespace color {
enum color_t {
Expand Down
Loading