Skip to content
This repository has been archived by the owner on Oct 3, 2018. It is now read-only.

Commit

Permalink
Added alignment attribute to address space structures and modified pa…
Browse files Browse the repository at this point in the history
…rallel localmemory initializer to work with apple driver (original version did crash the i5 cpu compiler) #20
  • Loading branch information
elhigu committed Aug 15, 2013
1 parent 62543c6 commit ab42d2c
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 16 deletions.
9 changes: 7 additions & 2 deletions TESTING.txt
Expand Up @@ -28,9 +28,14 @@ T3: POCL driver and Intel processor
Device: Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz.

T4: Apple driver and Intel processor
OS: Mac OSX 10.8.4
Driver: Apple
Device: Apple/Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz.

T5: POCL driver and Intel processor
OS: Mac OSX
Driver:
Device:
Driver: pocl-trunk rev.753 with optimized llvm 3.3
Device: Apple/Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz.

See the ISSUES.txt document about problems in different drivers.

Expand Down
7 changes: 6 additions & 1 deletion src/WebCLConsumer.cpp
Expand Up @@ -433,7 +433,12 @@ class MemoryAccessHandler {
analyser.getPointerAceesses();

std::map< unsigned, unsigned > maxAccess;

// add default 8 bit align
maxAccess[clang::LangAS::opencl_constant] = 8;
maxAccess[clang::LangAS::opencl_global] = 8;
maxAccess[clang::LangAS::opencl_local] = 8;
maxAccess[0] = 8;

for (WebCLAnalyser::MemoryAccessMap::iterator i = pointerAccesses.begin();
i != pointerAccesses.end(); ++i) {

Expand Down
28 changes: 20 additions & 8 deletions src/WebCLTransformer.cpp
Expand Up @@ -226,28 +226,28 @@ void WebCLTransformer::createAddressSpaceLimitsNullInitializer(
}

void WebCLTransformer::createAddressSpaceTypedef(
AddressSpaceInfo &as, const std::string &name)
AddressSpaceInfo &as, const std::string &name, const std::string &alignment)
{
if (!as.empty()) {
modulePrologue_ << "typedef struct "
<< addressSpaceInfoAsStruct(as)
<< " " << name << ";\n\n";
<< " __attribute__ ((aligned (" << alignment << "))) " << name << ";\n\n";
}
}

void WebCLTransformer::createPrivateAddressSpaceTypedef(AddressSpaceInfo &as)
{
createAddressSpaceTypedef(as, cfg_.privateRecordType_);
createAddressSpaceTypedef(as, cfg_.privateRecordType_, cfg_.getNameOfAlignMacro("private"));
}

void WebCLTransformer::createLocalAddressSpaceTypedef(AddressSpaceInfo &as)
{
createAddressSpaceTypedef(as, cfg_.localRecordType_);
createAddressSpaceTypedef(as, cfg_.localRecordType_, cfg_.getNameOfAlignMacro("local"));
}

void WebCLTransformer::createConstantAddressSpaceTypedef(AddressSpaceInfo &as)
{
createAddressSpaceTypedef(as, cfg_.constantRecordType_);
createAddressSpaceTypedef(as, cfg_.constantRecordType_, cfg_.getNameOfAlignMacro("constant"));
}

void WebCLTransformer::createAddressSpaceLimitsTypedef(
Expand Down Expand Up @@ -636,9 +636,20 @@ void WebCLTransformer::flushQueuedTransformations() {
void WebCLTransformer::addMinimumRequiredContinuousAreaLimit(unsigned addressSpace,
unsigned minWidthInBits)
{
modulePrologue_ << "#define " << cfg_.getNameOfSizeMacro(addressSpace) << " ("
<< "((" << minWidthInBits << " + (CHAR_BIT - 1)) / CHAR_BIT)"
<< ")\n";
preModulePrologue_ << "#define " << cfg_.getNameOfSizeMacro(addressSpace) << " ("
<< "((" << minWidthInBits << " + (CHAR_BIT - 1)) / CHAR_BIT)"
<< ")\n";

// get aligment rounded to next power of two
unsigned minAlignment = 1;
while (minWidthInBits != 0) {
minWidthInBits = minWidthInBits>>1;
minAlignment = minAlignment<<1;
}
minAlignment = minAlignment>>1;

preModulePrologue_ << "#define " << cfg_.getNameOfAlignMacro(addressSpace) << " "
<< "(" << minAlignment << "/CHAR_BIT)\n";
}

void WebCLTransformer::addAddressSpaceNull(std::ostream &out, unsigned addressSpace)
Expand Down Expand Up @@ -1091,6 +1102,7 @@ void WebCLTransformer::emitLimitMacros(std::ostream &out)

void WebCLTransformer::emitPrologue(std::ostream &out)
{
out << preModulePrologue_.str();
out << modulePrologue_.str();
emitGeneralCode(out);
emitLimitMacros(out);
Expand Down
6 changes: 5 additions & 1 deletion src/WebCLTransformer.hpp
Expand Up @@ -50,7 +50,7 @@ class WebCLTransformer : public WebCLReporter
/// Applies all AST transformations.
bool rewrite();

void createAddressSpaceTypedef(AddressSpaceInfo &as, const std::string &name);
void createAddressSpaceTypedef(AddressSpaceInfo &as, const std::string &name, const std::string &alignment);
void createPrivateAddressSpaceTypedef(AddressSpaceInfo &as);
void createLocalAddressSpaceTypedef(AddressSpaceInfo &as);
void createConstantAddressSpaceTypedef(AddressSpaceInfo &as);
Expand Down Expand Up @@ -141,6 +141,10 @@ class WebCLTransformer : public WebCLReporter
RequiredMacroSet usedClampMacros_;
FunctionPrologueMap kernelPrologues_;
FunctionPrologueMap functionPrologues_;

// this is stream for things that needs to be absolutely at first in program even before typedefs
std::stringstream preModulePrologue_;
// stream for other initializations at start of module like typedefs and address space structures
std::stringstream modulePrologue_;

// set to keep track that we are not doing paramRelocationInitializations multiple times
Expand Down
23 changes: 20 additions & 3 deletions src/WebCLTransformerConfiguration.cpp
Expand Up @@ -107,11 +107,28 @@ const std::string WebCLTransformerConfiguration::getNameOfLimitCheckMacro(
return result.str();
}

const std::string WebCLTransformerConfiguration::getNameOfSizeMacro(const std::string &asName) const
{
const std::string name =
macroPrefix_ + "_ADDRESS_SPACE_" + asName + "_MIN";
return name;
}

const std::string WebCLTransformerConfiguration::getNameOfSizeMacro(unsigned addressSpaceNum) const
{
const std::string name =
macroPrefix_ + "_ADDRESS_SPACE_" + getNameOfAddressSpace(addressSpaceNum) + "_MIN";
return name;
return getNameOfSizeMacro(getNameOfAddressSpace(addressSpaceNum));
}

const std::string WebCLTransformerConfiguration::getNameOfAlignMacro(const std::string &asName) const
{
const std::string name =
macroPrefix_ + "_ADDRESS_SPACE_" + asName + "_ALIGNMENT";
return name;
}

const std::string WebCLTransformerConfiguration::getNameOfAlignMacro(unsigned addressSpaceNum) const
{
return getNameOfAlignMacro(getNameOfAddressSpace(addressSpaceNum));
}

const std::string WebCLTransformerConfiguration::getNameOfLimitMacro() const
Expand Down
3 changes: 3 additions & 0 deletions src/WebCLTransformerConfiguration.hpp
Expand Up @@ -24,7 +24,10 @@ class WebCLTransformerConfiguration
const std::string getNameOfAddressSpaceNullPtrRef(unsigned addressSpaceNum) const;
const std::string getNameOfLimitCheckMacro(
unsigned addressSpaceNum, int limitCount) const;
const std::string getNameOfSizeMacro(const std::string &asName) const;
const std::string getNameOfSizeMacro(unsigned addressSpaceNum) const;
const std::string getNameOfAlignMacro(const std::string &asName) const;
const std::string getNameOfAlignMacro(unsigned addressSpaceNum) const;
const std::string getNameOfLimitMacro() const;
const std::string getNameOfAddressSpace(clang::QualType type) const;
const std::string getNameOfType(clang::QualType type) const;
Expand Down
3 changes: 2 additions & 1 deletion src/general.cl
Expand Up @@ -36,7 +36,7 @@ void _wcl_local_range_init(__local _WclInitType *begin, __local _WclInitType *en
get_local_id(2);
const size_t num_elements = stop - start;
const size_t item_elements = num_elements / xyz_items;

/*
__local uchar *item_begin = start + (item_index * item_elements);
__local const uchar *item_end = item_begin + item_elements;
for (__local uchar *item_i = item_begin; item_i < item_end; ++item_i)
Expand All @@ -46,6 +46,7 @@ void _wcl_local_range_init(__local _WclInitType *begin, __local _WclInitType *en
__local uchar *item_final = start + (loop_elements + item_index);
if (item_final < stop)
*item_final = _WCL_FILLCHAR;
*/
}

#endif // cl_khr_initialize_memory
Expand Down

0 comments on commit ab42d2c

Please sign in to comment.