added emulation of "soa" data types via shared-memory

This commit is contained in:
Evghenii
2014-01-23 16:17:06 +01:00
parent 0091973bca
commit da7a2c0c7f
5 changed files with 42 additions and 1 deletions

View File

@@ -168,11 +168,13 @@ DeclSpecs::GetBaseType(SourcePos pos) const {
retType = lApplyTypeQualifiers(typeQualifiers, retType, pos);
if (soaWidth > 0) {
#if 0 /* see stmt.cpp in DeclStmt::EmitCode for work-around of SOAType Declaration */
if (g->target->getISA() == Target::NVPTX)
{
Error(pos, "\"soa\" data types are currently not supported with \"nvptx\" target.");
return NULL;
}
#endif
const StructType *st = CastType<StructType>(retType);
if (st == NULL) {

View File

@@ -264,6 +264,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
return;
}
if (sym->storageClass == SC_STATIC) {
if (g->target->getISA() == Target::NVPTX && !sym->type->IsConstType())
@@ -328,7 +329,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
// Tell the FunctionEmitContext about the variable
ctx->EmitVariableDebugInfo(sym);
}
else if (sym->type->IsUniformType() &&
else if ((sym->type->IsUniformType() || sym->type->IsSOAType()) &&
/* NVPTX:
* only non-constant uniform data types are stored in shared memory
* constant uniform are automatically promoted to varying
@@ -357,6 +358,8 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
* instead of compile-time constants
*/
nel *= at->GetElementCount();
if (sym->type->IsSOAType())
nel *= sym->type->GetSOAWidth();
nat = new ArrayType(at->GetElementType(), nel);
variable = false;
}

View File

@@ -15,6 +15,16 @@ static void p(uniform float *uniform ptr) {
}
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
#ifdef __NVPTX__ /* soa is converted to shared memory story for now, use smaller amount to check the test */
soa<4> Point pts[10];
for (uniform int i = 0; i < 40; ++i) {
pts[i].x = b*i;
pts[i].y[0] = 2*b*i;
pts[i].y[1] = 2*b*i+1;
pts[i].y[2] = 2*b*i+2;
pts[i].z = 3*b*i;
}
#else
soa<4> Point pts[30];
for (uniform int i = 0; i < 120; ++i) {
pts[i].x = b*i;
@@ -23,6 +33,7 @@ export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
pts[i].y[2] = 2*b*i+2;
pts[i].z = 3*b*i;
}
#endif
float a = aFOO[programIndex];
a *= -1;

View File

@@ -16,6 +16,16 @@ static void p(uniform float *uniform ptr) {
}
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
#ifdef __NVPTX__ /* soa is converted to shared memory story for now, use smaller amount to check the test */
soa<4> Point pts[15];
for (uniform int i = 0; i < 60; ++i) {
pts[i].x = b*i;
pts[i].y[0] = 2*b*i;
pts[i].y[1] = 2*b*i+1;
pts[i].y[2] = 2*b*i+2;
pts[i].z = 3*b*i;
}
#else
soa<4> Point pts[40];
for (uniform int i = 0; i < 160; ++i) {
pts[i].x = b*i;
@@ -24,11 +34,14 @@ export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
pts[i].y[2] = 2*b*i+2;
pts[i].z = 3*b*i;
}
#endif
float a = aFOO[programIndex];
a *= -1;
Point vp = { a, { 2*a, 3*a, 4*a }, {5*a} };
#ifndef __NVPTX__
assert(2+programIndex < 160);
#endif
pts[2+programIndex] = vp;
RET[programIndex] = pts[programIndex].y[2];

View File

@@ -6,6 +6,17 @@ export uniform int width() { return programCount; }
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
float a = aFOO[programIndex];
#ifdef __NVPTX__ /* soa is converted to shared memory story for now, use smaller amount to check the test */
soa<8> Point pts[4];
//CO uniform Point pts[80];
foreach (i = 0 ... 40) {
pts[i].x = b*i;
pts[i].y[0] = 2*b*i;
pts[i].y[1] = 2*b*i+1;
pts[i].y[2] = 2*b*i+2;
pts[i].z = 3*b*i;
}
#else
soa<8> Point pts[10];
//CO uniform Point pts[80];
foreach (i = 0 ... 80) {
@@ -15,6 +26,7 @@ export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
pts[i].y[2] = 2*b*i+2;
pts[i].z = 3*b*i;
}
#endif
assert(programCount < 80);
RET[programIndex] = pts[programIndex].y[2];