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

Selective warnings #71

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/core/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ void Context::unregisterPlugin(Plugin *plugin)
m_plugins.remove(make_pair(plugin, false));
}

void Context::logError(const char* error) const
void Context::logError(const char* error, MessageType type) const
{
Message msg(ERROR, this);
Message msg(type, this);
msg << error << endl
<< msg.INDENT
<< "Kernel: " << msg.CURRENT_KERNEL << endl
Expand Down
2 changes: 1 addition & 1 deletion src/core/Context.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace oclgrind

Memory* getGlobalMemory() const;
bool isThreadSafe() const;
void logError(const char* error) const;
void logError(const char* error, MessageType type = OCLGRIND_ERROR) const;

// Simulation callbacks
void notifyInstructionExecuted(const WorkItem *workItem,
Expand Down
4 changes: 2 additions & 2 deletions src/core/KernelInvocation.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void KernelInvocation::run(const Context *context, Kernel *kernel,
<< endl << err.what()
<< endl << "When allocating kernel constants for '"
<< kernel->getName() << "'";
context->logError(info.str().c_str());
context->logError(info.str().c_str(), OCLGRIND_ERROR_FATAL);
return;
}

Expand Down Expand Up @@ -268,7 +268,7 @@ void KernelInvocation::runWorker()
info << "OCLGRIND FATAL ERROR "
<< "(" << err.getFile() << ":" << err.getLine() << ")"
<< endl << err.what();
m_context->logError(info.str().c_str());
m_context->logError(info.str().c_str(), OCLGRIND_ERROR_FATAL);

if (workerState.workGroup)
delete workerState.workGroup;
Expand Down
8 changes: 4 additions & 4 deletions src/core/WorkGroup.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ size_t WorkGroup::async_copy(
(itr->first.srcStride != copy.srcStride) ||
(itr->first.destStride != copy.destStride))
{
Context::Message msg(ERROR, m_context);
Context::Message msg(OCLGRIND_ERROR_DIVERGENCE, m_context);
msg << "Work-group divergence detected (async copy)" << endl
<< msg.INDENT
<< "Kernel: " << msg.CURRENT_KERNEL << endl
Expand Down Expand Up @@ -180,7 +180,7 @@ void WorkGroup::clearBarrier()
// Check for divergence
if (m_barrier->workItems.size() != m_workItems.size())
{
Context::Message msg(ERROR, m_context);
Context::Message msg(OCLGRIND_ERROR_DIVERGENCE, m_context);
msg << "Work-group divergence detected (barrier)" << endl
<< msg.INDENT
<< "Kernel: " << msg.CURRENT_KERNEL << endl
Expand Down Expand Up @@ -247,7 +247,7 @@ void WorkGroup::clearBarrier()
// Check that all work-items registered the copy
if (cItr->second.size() != m_workItems.size())
{
Context::Message msg(ERROR, m_context);
Context::Message msg(OCLGRIND_ERROR_DIVERGENCE, m_context);
msg << "Work-group divergence detected (async copy)" << endl
<< msg.INDENT
<< "Kernel: " << msg.CURRENT_KERNEL << endl
Expand Down Expand Up @@ -385,7 +385,7 @@ void WorkGroup::notifyBarrier(WorkItem *workItem,

if (divergence)
{
Context::Message msg(ERROR, m_context);
Context::Message msg(OCLGRIND_ERROR_DIVERGENCE, m_context);
msg << "Work-group divergence detected (barrier)" << endl
<< msg.INDENT
<< "Kernel: " << msg.CURRENT_KERNEL << endl
Expand Down
4 changes: 2 additions & 2 deletions src/core/WorkItem.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ INSTRUCTION(load)
if (address & (alignment-1))
{
m_context->logError("Invalid memory load - source pointer is "
"not aligned to the pointed type");
"not aligned to the pointed type", OCLGRIND_ERROR_UNALIGNED);
}

// Load data
Expand Down Expand Up @@ -1374,7 +1374,7 @@ INSTRUCTION(store)
if (address & (alignment-1))
{
m_context->logError("Invalid memory store - source pointer is "
"not aligned to the pointed type");
"not aligned to the pointed type", OCLGRIND_ERROR_UNALIGNED);
}

// Store data
Expand Down
22 changes: 11 additions & 11 deletions src/core/WorkItemBuiltins.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_add");
workItem->m_context->logError("Unaligned address on atomic_add", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicAdd, address, UARG(1));
result.setUInt(old);
Expand All @@ -298,7 +298,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_and");
workItem->m_context->logError("Unaligned address on atomic_and", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicAnd, address, UARG(1));
result.setUInt(old);
Expand All @@ -312,7 +312,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_cmpxchg");
workItem->m_context->logError("Unaligned address on atomic_cmpxchg", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomicCmpxchg(address, UARG(1), UARG(2));
result.setUInt(old);
Expand All @@ -326,7 +326,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_dec");
workItem->m_context->logError("Unaligned address on atomic_dec", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicDec, address);
result.setUInt(old);
Expand All @@ -340,7 +340,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_dec");
workItem->m_context->logError("Unaligned address on atomic_dec", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicInc, address);
result.setUInt(old);
Expand All @@ -354,7 +354,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_max");
workItem->m_context->logError("Unaligned address on atomic_max", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicMax, address, UARG(1));
result.setUInt(old);
Expand All @@ -368,7 +368,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_min");
workItem->m_context->logError("Unaligned address on atomic_min", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicMin, address, UARG(1));
result.setUInt(old);
Expand All @@ -382,7 +382,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_or");
workItem->m_context->logError("Unaligned address on atomic_or", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicOr, address, UARG(1));
result.setUInt(old);
Expand All @@ -396,7 +396,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_sub");
workItem->m_context->logError("Unaligned address on atomic_sub", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicSub, address, UARG(1));
result.setUInt(old);
Expand All @@ -410,7 +410,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_xchg");
workItem->m_context->logError("Unaligned address on atomic_xchg", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicXchg, address, UARG(1));
result.setUInt(old);
Expand All @@ -424,7 +424,7 @@ namespace oclgrind
size_t address = PARG(0);
// Verify the address is 4-byte aligned
if ((address & 0x3) != 0) {
workItem->m_context->logError("Unaligned address on atomic_xor");
workItem->m_context->logError("Unaligned address on atomic_xor", OCLGRIND_ERROR_UNALIGNED);
}
uint32_t old = memory->atomic(AtomicXor, address, UARG(1));
result.setUInt(old);
Expand Down
5 changes: 5 additions & 0 deletions src/core/common.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,11 @@ namespace oclgrind
}
}

MessageType getMessageBaseType(MessageType type)
{
return (MessageType)(type & 0x3);
}

FatalError::FatalError(const string& msg, const string& file, size_t line)
: std::runtime_error(msg)
{
Expand Down
21 changes: 17 additions & 4 deletions src/core/common.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,20 @@ namespace oclgrind
// Enumeration for different log message types
enum MessageType
{
DEBUG,
INFO,
WARNING,
ERROR,
// Base types
OCLGRIND_DEBUG = 0,
OCLGRIND_INFO = 1,
OCLGRIND_WARNING = 2,
OCLGRIND_ERROR = 3,
// Special warning types
OCLGRIND_WARNING_UNINITIALIZED = OCLGRIND_WARNING + 4,
// Special error types
OCLGRIND_ERROR_DIVERGENCE = OCLGRIND_ERROR + 4,
OCLGRIND_ERROR_INVALID_ACCESS = OCLGRIND_ERROR + 8,
OCLGRIND_ERROR_DATA_RACE = OCLGRIND_ERROR + 12,
OCLGRIND_ERROR_UNALIGNED = OCLGRIND_ERROR + 16,
OCLGRIND_ERROR_ARRAY_BOUNDS = OCLGRIND_ERROR + 20,
OCLGRIND_ERROR_FATAL = OCLGRIND_ERROR + 24,
};

// 3-dimensional size
Expand Down Expand Up @@ -188,6 +198,9 @@ namespace oclgrind
// Print data in a human readable format (according to its type)
void printTypedData(const llvm::Type *type, const unsigned char *data);

// Return the base type for a message type
MessageType getMessageBaseType(MessageType type);

// Exception class for raising fatal errors
class FatalError : std::runtime_error
{
Expand Down
38 changes: 37 additions & 1 deletion src/kernel/oclgrind-kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ int main(int argc, char *argv[])

static bool parseArguments(int argc, char *argv[])
{
// Collect all diagnostic options before writing them to environment
std::vector<const char*> diagnosticOptions;

for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "--build-options"))
if (!strncmp(argv[i], "-W", 2))
{
diagnosticOptions.push_back(argv[i]);
}
else if (!strcmp(argv[i], "--build-options"))
{
if (++i >= argc)
{
Expand Down Expand Up @@ -135,6 +142,15 @@ static bool parseArguments(int argc, char *argv[])
{
setEnvironment("OCLGRIND_QUICK", "1");
}
else if (!strcmp(argv[i], "--stop-errors"))
{
if (++i >= argc)
{
cerr << "Missing argument to --stop-errors" << endl;
return false;
}
setEnvironment("OCLGRIND_STOP_ERRORS", argv[i]);
}
else if (!strcmp(argv[i], "--uniform-writes"))
{
setEnvironment("OCLGRIND_UNIFORM_WRITES", "1");
Expand Down Expand Up @@ -174,6 +190,20 @@ static bool parseArguments(int argc, char *argv[])
}
}

// Set diagnostic options
if(diagnosticOptions.size())
{
std::stringstream options;
options << diagnosticOptions.front();

for(int i = 1; i < diagnosticOptions.size(); ++i)
{
options << " " << diagnosticOptions[i];
}

setEnvironment("OCLGRIND_DIAGNOSTIC_OPTIONS", options.str().c_str());
}

if (simfile == NULL)
{
printUsage();
Expand Down Expand Up @@ -210,6 +240,10 @@ static void printUsage()
"Redirect log/error messages to a file" << endl
<< " --max-errors NUM "
"Limit the number of error/warning messages" << endl
<< " -Wall "
"Enable all error/warning messages" << endl
<< " -W[no-]MSG_GROUP "
"Enable/disable specific message group" << endl
<< " --num-threads NUM "
"Set the number of worker threads to use" << endl
<< " --pch-dir DIR "
Expand All @@ -218,6 +252,8 @@ static void printUsage()
"Load colon separated list of plugin libraries" << endl
<< " -q --quick "
"Only run first and last work-group" << endl
<< " --stop-errors NUM "
"Abort the execution after NUM error/warning messages" << endl
<< " --uniform-writes "
"Don't suppress uniform write-write data-races" << endl
<< " --uninitialized "
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/InteractiveDebugger.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void InteractiveDebugger::kernelEnd(const KernelInvocation *kernelInvocation)

void InteractiveDebugger::log(MessageType type, const char *message)
{
if (type == ERROR)
if (getMessageBaseType(type) == OCLGRIND_ERROR)
m_forceBreak = true;
}

Expand Down
Loading