identified where to add shared memory. other problems showed up..
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
LLC=$HOME/usr/local/llvm/bin-trunk/bin/llc
|
LLC=$HOME/usr/local/llvm/bin-trunk/bin/llc
|
||||||
|
DIS=$HOME/usr/local/llvm/bin-3.2/bin/llvm-dis
|
||||||
|
|
||||||
ISPC=ispc
|
ISPC=ispc
|
||||||
PTXCC=ptxcc
|
PTXCC=ptxcc
|
||||||
$(cat $1 |grep -v 'width'|$ISPC --target=nvptx --emit-llvm -o -|$LLC -march=nvptx64 -mcpu=sm_35 -o $1.ptx) && \
|
PTXGEN=~/ptxgen
|
||||||
|
#$(cat $1 |grep -v 'width'|$ISPC --target=nvptx --emit-llvm -o -|$LLC -march=nvptx64 -mcpu=sm_35 -o $1.ptx) && \
|
||||||
|
$(cat $1 |grep -v 'width'|$ISPC --target=nvptx --emit-llvm -o -|$DIS -o $1_32_ptx.ll && $PTXGEN $1_32_ptx.ll > $1.ptx) && \
|
||||||
$($PTXCC $1.ptx -Xptxas=-v -o $1.ptx.o) && \
|
$($PTXCC $1.ptx -Xptxas=-v -o $1.ptx.o) && \
|
||||||
nvcc -o test_nvptx test_static_nvptx.cpp examples_ptx/nvcc_helpers.cu examples_ptx/ispc_malloc.cpp $1.ptx.o -arch=sm_35 -Iexamples_ptx/ -D_CUDA_ -lcudadevrt -DTEST_SIG=$2
|
nvcc -o test_nvptx test_static_nvptx.cpp examples_ptx/nvcc_helpers.cu examples_ptx/ispc_malloc.cpp $1.ptx.o -arch=sm_35 -Iexamples_ptx/ -D_CUDA_ -lcudadevrt -DTEST_SIG=$2
|
||||||
|
|
||||||
|
|||||||
68
stmt.cpp
68
stmt.cpp
@@ -206,9 +206,10 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sym->storageClass == SC_STATIC) {
|
if (sym->storageClass == SC_STATIC) {
|
||||||
if (g->target->getISA() == Target::NVPTX)
|
|
||||||
if (!sym->type->IsConstType())
|
if (g->target->getISA() == Target::NVPTX && !sym->type->IsConstType())
|
||||||
Error(initExpr->pos, "Non-constant static variable ""\"%s\" is not supported with ""\"cuda\" target.",
|
Error(sym->pos,
|
||||||
|
"Non-constant static variable ""\"%s\" is not supported with ""\"nvptx\" target.",
|
||||||
sym->name.c_str());
|
sym->name.c_str());
|
||||||
|
|
||||||
// For static variables, we need a compile-time constant value
|
// For static variables, we need a compile-time constant value
|
||||||
@@ -247,10 +248,70 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
|
|||||||
llvm::Twine("static_") +
|
llvm::Twine("static_") +
|
||||||
llvm::Twine(sym->pos.first_line) +
|
llvm::Twine(sym->pos.first_line) +
|
||||||
llvm::Twine("_") + sym->name.c_str());
|
llvm::Twine("_") + sym->name.c_str());
|
||||||
|
#if 0
|
||||||
|
NULL,
|
||||||
|
llvm::GlobalVariable::NotThreadLocal,
|
||||||
|
3);
|
||||||
|
#endif
|
||||||
// Tell the FunctionEmitContext about the variable
|
// Tell the FunctionEmitContext about the variable
|
||||||
ctx->EmitVariableDebugInfo(sym);
|
ctx->EmitVariableDebugInfo(sym);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#if 0 /* PTX:: shared/uniform data types are here */
|
||||||
|
if (sym->type->IsArrayType() && sym->type->IsUniformType()
|
||||||
|
&& g->target->getISA() == Target::NVPTX)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
if (initExpr != NULL)
|
||||||
|
Error(initExpr->pos, "Initializer for static variable "
|
||||||
|
"\"%s\" must be a constant.", sym->name.c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PerformanceWarning(sym->pos,
|
||||||
|
"\"uniform\" arrays may be slow with \"nvptx\" target. Use \"varying\" if possible.");
|
||||||
|
|
||||||
|
llvm::Constant *cinit = NULL;
|
||||||
|
if (initExpr != NULL)
|
||||||
|
{
|
||||||
|
if (PossiblyResolveFunctionOverloads(initExpr, sym->type) == false)
|
||||||
|
continue;
|
||||||
|
// FIXME: we only need this for function pointers; it was
|
||||||
|
// already done for atomic types and enums in
|
||||||
|
// DeclStmt::TypeCheck()...
|
||||||
|
if (dynamic_cast<ExprList *>(initExpr) == NULL) {
|
||||||
|
initExpr = TypeConvertExpr(initExpr, sym->type,
|
||||||
|
"initializer");
|
||||||
|
// FIXME: and this is only needed to re-establish
|
||||||
|
// constant-ness so that GetConstant below works for
|
||||||
|
// constant artithmetic expressions...
|
||||||
|
initExpr = ::Optimize(initExpr);
|
||||||
|
}
|
||||||
|
|
||||||
|
cinit = initExpr->GetConstant(sym->type);
|
||||||
|
}
|
||||||
|
if (cinit == NULL)
|
||||||
|
cinit = llvm::Constant::getNullValue(llvmType);
|
||||||
|
|
||||||
|
// Allocate space for the static variable in global scope, so
|
||||||
|
// that it persists across function calls
|
||||||
|
sym->storagePtr =
|
||||||
|
new llvm::GlobalVariable(*m->module, llvmType,
|
||||||
|
sym->type->IsConstType(),
|
||||||
|
llvm::GlobalValue::InternalLinkage, cinit,
|
||||||
|
llvm::Twine("local") +
|
||||||
|
llvm::Twine(sym->pos.first_line) +
|
||||||
|
llvm::Twine("_") + sym->name.c_str(),
|
||||||
|
NULL,
|
||||||
|
llvm::GlobalVariable::NotThreadLocal,
|
||||||
|
/*AddressSpace=*/ 3);
|
||||||
|
llvm::GlobalVariable *var = llvm::dyn_cast<llvm::GlobalVariable>(sym->storagePtr);
|
||||||
|
var->setAlignment(128);
|
||||||
|
// Tell the FunctionEmitContext about the variable
|
||||||
|
ctx->EmitVariableDebugInfo(sym);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
// For non-static variables, allocate storage on the stack
|
// For non-static variables, allocate storage on the stack
|
||||||
sym->storagePtr = ctx->AllocaInst(llvmType, sym->name.c_str());
|
sym->storagePtr = ctx->AllocaInst(llvmType, sym->name.c_str());
|
||||||
|
|
||||||
@@ -263,6 +324,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
|
|||||||
InitSymbol(sym->storagePtr, sym->type, initExpr, ctx, sym->pos);
|
InitSymbol(sym->storagePtr, sym->type, initExpr, ctx, sym->pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user