Skip to content

Commit

Permalink
[Props] Updated how verbose works
Browse files Browse the repository at this point in the history
  • Loading branch information
dmed256 committed Mar 30, 2018
1 parent 7b5dad1 commit 882ed5f
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ test:
cd $(OCCA_DIR)/examples/$$dir && \
rm -f main && \
CXXFLAGS='-g' make && \
./main; \
OCCA_VERBOSE=1 ./main; \
done
#=================================================

Expand Down
3 changes: 2 additions & 1 deletion include/occa/modes/opencl/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ namespace occa {
const std::string &kernelName,
const std::string &flags = "",
hash_t hash = hash_t(),
const std::string &sourceFile = "");
const std::string &sourceFile = "",
const occa::properties &properties = occa::properties());

void buildKernelFromBinary(info_t &info_,
const unsigned char *content,
Expand Down
42 changes: 11 additions & 31 deletions include/occa/tools/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ namespace occa {
}

template <class TM>
inline std::string toString(const TM &t) {
std::string toString(const TM &t) {
std::stringstream ss;
ss << t;
return ss.str();
}

template <class TM>
inline std::string toString(const std::vector<TM> &v) {
std::string toString(const std::vector<TM> &v) {
const int size = (int) v.size();
std::stringstream ss;
ss << '[';
Expand All @@ -99,26 +99,16 @@ namespace occa {
}

template <>
inline std::string toString<std::string>(const std::string &t) {
return t;
}
std::string toString<std::string>(const std::string &t);

template <>
inline std::string toString<float>(const float &t) {
std::stringstream ss;
ss << std::scientific << std::setprecision(8) << t << 'f';
return ss.str();
}
std::string toString<float>(const float &t);

template <>
inline std::string toString<double>(const double &t) {
std::stringstream ss;
ss << std::scientific << std::setprecision(16) << t;
return ss.str();
}
std::string toString<double>(const double &t);

template <class TM>
inline TM fromString(const std::string &s) {
TM fromString(const std::string &s) {
std::stringstream ss;
TM t;
ss << s;
Expand All @@ -127,18 +117,13 @@ namespace occa {
}

template <>
inline bool fromString(const std::string &s) {
if (s == "0") {
return false;
}
const std::string sUp = uppercase(s);
return !((sUp == "N") ||
(sUp == "NO") ||
(sUp == "FALSE"));
}
bool fromString(const std::string &s);

template <>
std::string fromString(const std::string &s);

template <class TM>
inline std::vector<TM> listFromString(const std::string &s) {
std::vector<TM> listFromString(const std::string &s) {
std::string str = strip(s);
const int chars = (int) str.size();
if (chars && str[chars - 1] == ']') {
Expand All @@ -159,11 +144,6 @@ namespace occa {
return ret;
}

template <>
inline std::string fromString(const std::string &s) {
return s;
}

inline bool startsWith(const std::string &s,
const std::string &match) {
const int matchChars = (int) match.size();
Expand Down
33 changes: 15 additions & 18 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ namespace occa {
}
}

std::cout << defaults << '\n';

setDHandle(occa::newModeDevice(defaults + props));

stream newStream = createStream();
Expand Down Expand Up @@ -297,9 +295,6 @@ namespace occa {
std::string devHash = dHandle->hash().toFullString();
strVector dirs = io::directories("occa://" + library);
const int dirCount = (int) dirs.size();

const bool isVerbose = settings().get("verbose-compilation", true);
settings()["verbose-compilation"] = false;
int kernelsLoaded = 0;

for (int d = 0; d < dirCount; ++d) {
Expand All @@ -313,14 +308,19 @@ namespace occa {
if (info["device/hash"].string() != devHash) {
continue;
}

++kernelsLoaded;

const std::string sourceFilename = dirs[d] + kc::parsedSourceFile;

json &kInfo = info["kernel"];
hash_t hash = hash_t::fromString(kInfo["hash"].string());
jsonArray metadataArray = kInfo["metadata"].array();
occa::properties kernelProps = kInfo["props"];
const std::string sourceFilename = dirs[d] + kc::parsedSourceFile;

const bool kernelHasVerbose = kernelProps.has("verbose");
const bool kernelIsVerbose = (kernelHasVerbose &&
kernelProps.get("verbose", false));
kernelProps["verbose"] = false;

const int kernels = metadataArray.size();
for (int k = 0; k < kernels; ++k) {
Expand All @@ -333,17 +333,22 @@ namespace occa {
metadata);
}
}

if (kernelIsVerbose) {
kernelProps["verbose"] = true;
}
}

settings()["verbose-compilation"] = isVerbose;
if (isVerbose && kernelsLoaded) {
if (properties().get("verbose", false) && kernelsLoaded) {
std::cout << "Loaded " << kernelsLoaded;
if (library.size()) {
std::cout << " ["<< library << "]";
} else {
std::cout << " cached";
}
std::cout << ((kernelsLoaded == 1) ? " kernel\n" : " kernels\n");
std::cout << ((kernelsLoaded == 1)
? " kernel\n"
: " kernels\n");
}
}

Expand Down Expand Up @@ -418,8 +423,6 @@ namespace occa {

// Load nested kernels
if (metadata.nestedKernels) {
const bool vc_f = settings()["verbose-compilation"];

for (int ki = 0; ki < metadata.nestedKernels; ++ki) {
kernelMetadata sMetadata = metadata.getNestedKernelMetadata(ki);
const std::string &sKerName = sMetadata.name;
Expand All @@ -428,13 +431,7 @@ namespace occa {
sKer.kHandle->metadata = sMetadata;

launchKHandle->nestedKernels.push_back(sKer);

// Only show compilation the first time
if (ki == 0) {
settings()["verbose-compilation"] = false;
}
}
settings()["verbose-compilation"] = vc_f;
}
return occa::kernel(launchKHandle);
}
Expand Down
22 changes: 16 additions & 6 deletions src/modes/cuda/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace occa {
name = kernelName;
properties += props;

const bool verbose = properties.get("verbose", false);

if (properties.get<std::string>("compilerFlags").find("-arch=sm_") == std::string::npos) {
cuda::device &dev = *((cuda::device*) dHandle);
const int major = dev.archMajorVersion;
Expand All @@ -72,7 +74,7 @@ namespace occa {
}

if (foundBinary) {
if (settings().get("verbose-compilation", true)) {
if (verbose) {
std::cout << "Found cached binary of [" << io::shortname(filename)
<< "] in [" << io::shortname(binaryFile) << "]\n";
}
Expand All @@ -93,11 +95,11 @@ namespace occa {
ss.str(),
properties["footer"]);

if (settings().get("verbose-compilation", true)) {
if (verbose) {
std::cout << "Compiling [" << kernelName << "]\n";
}

//---[ PTX Check Command ]----------
//---[ PTX Check Command ]--------
std::stringstream command;
if (properties.has("compilerEnvScript")) {
command << properties["compilerEnvScript"] << " && ";
Expand All @@ -114,8 +116,11 @@ namespace occa {
<< " -x cu -c " << cachedSourceFile
<< " -o " << ptxBinaryFile;

if (!verbose) {
command << " > /dev/null 2>&1";
}
const std::string &ptxCommand = command.str();
if (settings().get("verbose-compilation", true)) {
if (verbose) {
std::cout << "Compiling [" << kernelName << "]\n" << ptxCommand << "\n";
}

Expand All @@ -124,8 +129,9 @@ namespace occa {
#else
ignoreResult( system(("\"" + ptxCommand + "\"").c_str()) );
#endif
//================================

//---[ Compiling Command ]----------
//---[ Compiling Command ]--------
command.str("");
command << properties["compiler"]
<< ' ' << properties["compilerFlags"]
Expand All @@ -138,8 +144,11 @@ namespace occa {
<< " -x cu " << cachedSourceFile
<< " -o " << binaryFile;

if (!verbose) {
command << " > /dev/null 2>&1";
}
const std::string &sCommand = command.str();
if (settings().get("verbose-compilation", true)) {
if (verbose) {
std::cout << sCommand << '\n';
}

Expand All @@ -150,6 +159,7 @@ namespace occa {
OCCA_ERROR("Compilation error",
false);
}
//================================

const CUresult moduleLoadError = cuModuleLoad(&cuModule,
binaryFile.c_str());
Expand Down
6 changes: 4 additions & 2 deletions src/modes/opencl/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace occa {
}

if (foundBinary) {
if (settings().get("verbose-compilation", true)) {
if (properties.get("verbose", false)) {
std::cout << "Found cached binary of [" << io::shortname(filename)
<< "] in [" << io::shortname(binaryFile) << "]\n";
}
Expand All @@ -96,7 +96,9 @@ namespace occa {
cFunction.c_str(), cFunction.size(),
kernelName,
properties["compilerFlags"],
hash, sourceFile);
hash,
sourceFile,
properties);
clKernel = clInfo.clKernel;

opencl::saveProgramBinary(clInfo, binaryFile, hash, hashTag);
Expand Down
9 changes: 6 additions & 3 deletions src/modes/opencl/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,12 @@ namespace occa {
const std::string &kernelName,
const std::string &flags,
hash_t hash,
const std::string &sourceFile) {
const std::string &sourceFile,
const occa::properties &properties) {
cl_int error;

const bool verbose = properties.get("verbose", false);

info_.clProgram = clCreateProgramWithSource(info_.clContext, 1,
(const char **) &content,
&contentBytes,
Expand All @@ -276,7 +279,7 @@ namespace occa {
if (error && hash.initialized) {
io::releaseHash(hash, hashTag);
}
if (settings().get("verbose-compilation", true)) {
if (verbose) {
if (hash.initialized) {
std::cout << "OpenCL compiling " << kernelName
<< " from [" << sourceFile << "]";
Expand Down Expand Up @@ -330,7 +333,7 @@ namespace occa {
}
OCCA_OPENCL_ERROR("Kernel (" + kernelName + "): Creating Kernel", error);

if (settings().get("verbose-compilation", true)) {
if (verbose) {
if (sourceFile.size()) {
std::cout << "OpenCL compiled " << kernelName << " from [" << sourceFile << "]";

Expand Down
5 changes: 3 additions & 2 deletions src/modes/serial/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace occa {
properties += props;

const bool isLaunchKernel = props.has("defines/OCCA_LAUNCH_KERNEL");
const bool verbose = properties.get("verbose", false);

const std::string sourceFile = (isLaunchKernel
? getLaunchSourceFilename(filename, hash)
Expand All @@ -66,7 +67,7 @@ namespace occa {
}

if (foundBinary) {
if (settings().get("verbose-compilation", true)) {
if (verbose) {
std::cout << "Found cached binary of [" << io::shortname(filename) << "] in [" << io::shortname(binaryFile) << "]\n";
}
return buildFromBinary(binaryFile, kernelName, props);
Expand Down Expand Up @@ -128,7 +129,7 @@ namespace occa {

const std::string &sCommand = command.str();

if (settings().get("verbose-compilation", true)) {
if (verbose) {
std::cout << "Compiling [" << kernelName << "]\n" << sCommand << "\n";
}

Expand Down
12 changes: 9 additions & 3 deletions src/tools/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ namespace occa {

void envInitializer_t::initSettings() {
properties &settings_ = baseSettings();
settings_["version"] = OCCA_VERSION_STR;
settings_["oklVersion"] = OKL_VERSION_STR;
settings_["verbose-compilation"] = env::get("OCCA_VERBOSE", false);
settings_["version"] = OCCA_VERSION_STR;
settings_["okl-version"] = OKL_VERSION_STR;

const bool isVerbose = env::get("OCCA_VERBOSE", false);
if (isVerbose) {
settings_["device/verbose"] = true;
settings_["kernel/verbose"] = true;
settings_["memory/verbose"] = true;
}
}

void envInitializer_t::initSignalHandling() {
Expand Down
Loading

0 comments on commit 882ed5f

Please sign in to comment.