summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-09-17 17:59:18 +0000
committerTuowen Zhao <ztuowen@gmail.com>2016-09-17 17:59:18 +0000
commitcfafd2ffcad803e7bb02b60c085eafd73f28f87a (patch)
treed84324500a8b91dfea1a36ed96db5345c57b47b4
parent2fc34985f331c8d7b92969c5c657cb24f340ce25 (diff)
downloadchill-cfafd2ffcad803e7bb02b60c085eafd73f28f87a.tar.gz
chill-cfafd2ffcad803e7bb02b60c085eafd73f28f87a.tar.bz2
chill-cfafd2ffcad803e7bb02b60c085eafd73f28f87a.zip
cleanup
-rw-r--r--chill/include/chillmodule.hh4
-rw-r--r--chill/src/chill_run.cc305
-rw-r--r--chill/src/chill_run_util.cc9
-rw-r--r--chill/src/chillmodule.cc1033
4 files changed, 1 insertions, 1350 deletions
diff --git a/chill/include/chillmodule.hh b/chill/include/chillmodule.hh
index a64ad1b..2cb6587 100644
--- a/chill/include/chillmodule.hh
+++ b/chill/include/chillmodule.hh
@@ -11,11 +11,9 @@
//static PyMethodDef ChillMethods[] ;
-#ifndef CUDACHILL
void finalize_loop(int loop_num_start, int loop_num_end);
int get_loop_num_start();
int get_loop_num_end();
-#endif
-
PyMODINIT_FUNC initchill() ; // pass C methods to python
+
#endif
diff --git a/chill/src/chill_run.cc b/chill/src/chill_run.cc
index 59cd6e5..afebbb4 100644
--- a/chill/src/chill_run.cc
+++ b/chill/src/chill_run.cc
@@ -1,50 +1,17 @@
#include "chilldebug.h"
-// this is a little messy. the Makefile should be able to define one or the other
-#ifndef PYTHON
-#ifndef LUA
-#define LUA
-#endif
-#endif
-
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-//#include "chill_env.hh"
#include "loop.hh"
#include <omega.h>
#include "ir_code.hh"
-
-#ifdef CUDACHILL
-
-#ifdef BUILD_ROSE
-#include "loop_cuda_rose.hh"
-#include "ir_cudarose.hh"
-#elif BUILD_SUIF
-#include "loop_cuda.hh"
-#include "ir_cudasuif.hh"
-#endif
-
-#else
-
-#ifdef BUILD_ROSE
#include "ir_rose.hh"
-#elif BUILD_SUIF
-#include "ir_suif.hh"
-#endif
-#endif
-
-#ifdef LUA
-#define lua_c //Get the configuration defines for doing an interactive shell
-#include <lua.hpp> //All lua includes wrapped in extern "C"
-#include "chill_env.hh" // Lua wrapper functions for CHiLL
-#elif PYTHON
#include "chillmodule.hh" // Python wrapper functions for CHiLL
-#endif
//---
// CHiLL globals
@@ -57,181 +24,6 @@ bool is_interactive = false;
std::vector<IR_Control *> ir_controls;
std::vector<int> loops;
-// this whole section belongs somewhere else
-#ifdef LUA
-//---
-// Interactive mode functions, directly copied out of lua.c
-//---
-// The Lua interpreter state
-static lua_State *globalL = NULL;
-static const char *progname = "CHiLL";
-
-static void lstop (lua_State *L, lua_Debug *ar) {
- (void)ar; /* unused arg. */
- lua_sethook(L, NULL, 0, 0);
- luaL_error(L, "interrupted!");
-}
-
-
-static void laction (int i) {
- signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
- terminate process (default action) */
- lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
-}
-
-
-static void l_message (const char *pname, const char *msg) {
- if (pname) fprintf(stderr, "%s: ", pname);
- fprintf(stderr, "%s\n", msg);
- fflush(stderr); // ? does this do anything ?
-}
-
-
-static int report (lua_State *L, int status) {
- if (status && !lua_isnil(L, -1)) {
- const char *msg = lua_tostring(L, -1);
- if (msg == NULL) msg = "(error object is not a string)";
- l_message(progname, msg);
- lua_pop(L, 1);
- }
- return status;
-}
-
-
-static int traceback (lua_State *L) {
- if (!lua_isstring(L, 1)) /* 'message' not a string? */
- return 1; /* keep it intact */
- lua_getfield(L, LUA_GLOBALSINDEX, "debug");
- if (!lua_istable(L, -1)) {
- lua_pop(L, 1);
- return 1;
- }
- lua_getfield(L, -1, "traceback");
- if (!lua_isfunction(L, -1)) {
- lua_pop(L, 2);
- return 1;
- }
- lua_pushvalue(L, 1); /* pass error message */
- lua_pushinteger(L, 2); /* skip this function and traceback */
- lua_call(L, 2, 1); /* call debug.traceback */
- return 1;
-}
-
-
-static int docall (lua_State *L, int narg, int clear) {
- DEBUG_PRINT("\ndocall()\n");
- int status;
- int base = lua_gettop(L) - narg; /* function index */
- lua_pushcfunction(L, traceback); /* push traceback function */
- lua_insert(L, base); /* put it under chunk and args */
- signal(SIGINT, laction);
-
- DEBUG_PRINT("status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);\n");
-
- status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
- signal(SIGINT, SIG_DFL);
- lua_remove(L, base); /* remove traceback function */
- /* force a complete garbage collection in case of errors */
- if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
- return status;
-}
-
-static int dofile (lua_State *L, const char *name) {
- int status = luaL_loadfile(L, name) || docall(L, 0, 1);
- return report(L, status);
-}
-
-static const char *get_prompt (lua_State *L, int firstline) {
- const char *p;
- lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2");
- p = lua_tostring(L, -1);
- if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
- lua_pop(L, 1); /* remove global */
- return p;
-}
-
-
-static int incomplete (lua_State *L, int status) {
- if (status == LUA_ERRSYNTAX) {
- size_t lmsg;
- const char *msg = lua_tolstring(L, -1, &lmsg);
- const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
- if (strstr(msg, LUA_QL("<eof>")) == tp) {
- lua_pop(L, 1);
- return 1;
- }
- }
- return 0; /* else... */
-}
-
-
-static int pushline (lua_State *L, int firstline) {
- char buffer[LUA_MAXINPUT];
- char *b = buffer;
- size_t l;
- const char *prmt = get_prompt(L, firstline);
- if (lua_readline(L, b, prmt) == 0)
- return 0; /* no input */
- l = strlen(b);
- if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
- b[l-1] = '\0'; /* remove it */
- if (firstline && b[0] == '=') /* first line starts with `=' ? */
- lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
- else
- lua_pushstring(L, b);
- lua_freeline(L, b);
- return 1;
-}
-
-
-static int loadline (lua_State *L) {
- int status;
- lua_settop(L, 0);
- if (!pushline(L, 1))
- return -1; /* no input */
- for (;;) { /* repeat until gets a complete line */
- status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
- if (!incomplete(L, status)) break; /* cannot try to add lines? */
- if (!pushline(L, 0)) /* no more input? */
- return -1;
- lua_pushliteral(L, "\n"); /* add a new line... */
- lua_insert(L, -2); /* ...between the two lines */
- lua_concat(L, 3); /* join them */
- }
- lua_saveline(L, 1);
- lua_remove(L, 1); /* remove line */
- return status;
-}
-
-
-static void dotty (lua_State *L) {
- int status;
- const char *oldprogname = progname;
- progname = NULL;
- while ((status = loadline(L)) != -1) {
- if (status == 0) status = docall(L, 0, 0);
- report(L, status);
- if(repl_stop)
- break;
- if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
- lua_getglobal(L, "print");
- lua_insert(L, 1);
- if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
- l_message(progname, lua_pushfstring(L,
- "error calling " LUA_QL("print") " (%s)",
- lua_tostring(L, -1)));
- }
- }
- lua_settop(L, 0); /* clear stack */
- fputs("\n", stdout);
- fflush(stdout);
- progname = oldprogname;
-}
-#endif
-
-//---
-//---
-
//---
// CHiLL program main
// Initialize state and run script or interactive mode
@@ -246,7 +38,6 @@ int main( int argc, char* argv[] )
int fail = 0;
-#ifdef PYTHON
// Create PYTHON interpreter
/* Pass argv[0] to the Python interpreter */
Py_SetProgramName(argv[0]);
@@ -258,17 +49,6 @@ int main( int argc, char* argv[] )
initchill();
if (argc == 2) {
-/* #ifdef CUDACHILL --- This code is for translating lua to python before interprating. ---
- //DEBUG_PRINT("\ncalling python\n");
- // file interpretlua.py has routines to read the lua transformation file
- PyRun_SimpleString("from interpretlua import *");
- //DEBUG_PRINT("DONE calling python import of functions\n\n");
- char pythoncommand[800];
- sprintf(pythoncommand, "\n\ndopytransform(\"%s\")\0", argv[1]);
- //DEBUG_PRINT("in C, running python command '%s'\n", pythoncommand);
-
- PyRun_SimpleString( pythoncommand );
- #else*/
FILE* f = fopen(argv[1], "r");
if(!f){
printf("can't open script file \"%s\"\n", argv[1]);
@@ -293,102 +73,17 @@ int main( int argc, char* argv[] )
}
//printf("DONE with PyRun_SimpleString()\n");
-// #endif --- endif for CUDACHILL ---
-#endif
- //END python setup
-#ifdef LUA
-
- //Create interpreter
- lua_State* L = lua_open();
- globalL = L;
-
- //Initialize the std libs
- luaL_openlibs(L);
-
- //Initialize globals
- register_globals(L);
-
- //Register CHiLL functions
- register_functions(L);
-
- if (argc == 2) {
- //---
- // Run a CHiLL script from a file
- //---
-
- //Check that the file can be opened
- FILE* f = fopen(argv[1],"r");
- if(!f){
- printf("can't open script file \"%s\"\n", argv[1]);
- exit(-1);
- }
- fclose(f);
-
- DEBUG_PRINT("\n*********************evaluating file '%s'\n", argv[1]);
-
- //Evaluate the file
- fail = dofile(L, argv[1]);
- if(!fail){
- fprintf(stderr, "script success!\n");
- }
- }
- if (argc == 1 && isatty((int)fileno(stdin))) {
- //---
- // Run a CHiLL interpreter
- //---
- printf("CUDA-CHiLL v0.2.1 (built on %s)\n", CHILL_BUILD_DATE);
- printf("Copyright (C) 2008 University of Southern California\n");
- printf("Copyright (C) 2009-2012 University of Utah\n");
- is_interactive = true; // let the lua interpreter know.
- fflush(stdout);
- dotty(L);
- //Not sure if we should set fail from interactive mode
- printf("CUDA-CHiLL ending...\n");
- fflush(stdout);
- }
-#endif
-
if (!fail && ir_code != NULL && myloop != NULL && myloop->stmt.size() != 0 && !myloop->stmt[0].xform.is_null()) {
-#ifdef CUDACHILL
- int lnum;
- #ifdef PYTHON
- lnum = 0;
- #else
- lnum = get_loop_num( L );
- #endif
- #ifdef BUILD_ROSE
- ((IR_cudaroseCode *)(ir_code))->commit_loop(myloop, lnum);
- #elif BUILD_SUIF
- ((IR_cudasuifCode *)(ir_code))->commit_loop(myloop, lnum);
- #endif
-#else
int lnum_start;
int lnum_end;
- #ifdef PYTHON
lnum_start = get_loop_num_start();
lnum_end = get_loop_num_end();
DEBUG_PRINT("calling ROSE code gen? loop num %d\n", lnum);
- #else
- lnum_start = get_loop_num_start(L);
- lnum_end = get_loop_num_end(L);
- DEBUG_PRINT("calling ROSE code gen? loop num %d - %d\n", lnum_start, lnum_end);
- #endif
-#endif
- #ifdef BUILD_ROSE
finalize_loop(lnum_start, lnum_end);
- //((IR_roseCode*)(ir_cide))->commit_loop(myloop, lnum);
((IR_roseCode*)(ir_code))->finalizeRose();
- //#elif BUILD_SUIF
- //((IR_suifCode*)(ir_code))->commit_loop(myloop, lnum);
- #endif
delete ir_code;
}
-#ifdef PYTHON
Py_Finalize();
-#endif
-#ifdef LUA
- lua_close(L);
-#endif
return 0;
}
diff --git a/chill/src/chill_run_util.cc b/chill/src/chill_run_util.cc
index 566bc61..29568e7 100644
--- a/chill/src/chill_run_util.cc
+++ b/chill/src/chill_run_util.cc
@@ -118,12 +118,3 @@ simap_t* make_cond_item_level(int n) {
return nmap;
}
-/*simap_t* make_cond_item_variable(const char* varname) {
- simap_t* nmap = new simap_t();
-#ifdef PYTHON
- PyObject* globals = PyEval_GetGlobals();
- PyObject* itemval = PyDict_GetItemString(globals, varname);
-
-#elif LUA
-#endif
-}*/
diff --git a/chill/src/chillmodule.cc b/chill/src/chillmodule.cc
index fbeb477..36f810e 100644
--- a/chill/src/chillmodule.cc
+++ b/chill/src/chillmodule.cc
@@ -3,17 +3,6 @@
#include "chilldebug.h"
-#ifdef CUDACHILL
-
-#include "rose.h" // ??
-#include "loop_cuda_rose.hh"
-#include "ir_rose.hh"
-#include "ir_cudarose.hh"
-
-#include <vector>
-
-#else
-
#include "chill_run_util.hh"
#include <signal.h>
@@ -24,33 +13,16 @@
#include <omega.h>
#include "loop.hh"
#include "ir_code.hh"
-#ifdef BUILD_ROSE
#include "ir_rose.hh"
-#elif BUILD_SUIF
-#include "ir_suif.hh"
-#endif
-
-#endif
#include "chillmodule.hh"
-// TODO
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE
#include <Python.h>
using namespace omega;
-// -- Cuda CHiLL global variables --
-#ifdef CUDACHILL
-
-extern LoopCuda *myloop;
-extern IR_Code *ir_code;
-extern std::vector<IR_Control *> ir_controls;
-extern std::vector<int> loops;
-
-#else
-
extern Loop *myloop;
extern IR_Code *ir_code;
extern bool is_interactive;
@@ -65,12 +37,9 @@ int loop_end_num;
extern std::vector<IR_Control *> ir_controls;
extern std::vector<int> loops;
-#endif
-
// ----------------------- //
// CHiLL support functions //
// ----------------------- //
-#ifndef CUDACHILL
// not sure yet if this actually needs to be exposed to the python interface
// these four functions are here to maintain similarity to the Lua interface
int get_loop_num_start() {
@@ -123,19 +92,10 @@ static void init_loop(int loop_num_start, int loop_num_end) {
}
else {
if (ir_code == NULL) {
- #ifdef BUILD_ROSE
if (procedure_name.empty())
procedure_name = "main";
- #elif BUILD_SUIF
- if (procedure_number == -1)
- procedure_number = 0;
- #endif
- #ifdef BUILD_ROSE
ir_code = new IR_roseCode(source_filename.c_str(), procedure_name.c_str());
- #elif BUILD_SUIF
- ir_code = new IR_suifCode(source_filename.c_str(), procedure_name.c_str());
- #endif
IR_Block *block = ir_code->GetCode();
ir_controls = ir_code->FindOneLevelControlStructure(block);
@@ -175,7 +135,6 @@ static void init_loop(int loop_num_start, int loop_num_end) {
delete block;
//if (is_interactive) printf("%s ", PROMPT_STRING);
}
-#endif
// ----------------------- //
// Python support funcions //
@@ -315,962 +274,6 @@ static bool tointmatrix(PyObject* args, int index, std::vector<std::vector<int>
return true;
}
-#ifdef CUDACHILL
-// ------------------------------ //
-// Cuda CHiLL interface functions //
-// ------------------------------ //
-
-static PyObject *
-chill_print_code(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("\nC print_code() PY\n");
-
- myloop->printCode();
-
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-
-}
-
-static PyObject *
-chill_print_ri(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("\nC chill_print_ri() called from python\n");
- myloop->printRuntimeInfo();
- DEBUG_PRINT("\n");
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-}
-
-static PyObject *
-chill_print_idx(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("\nC chill_print_idx() called from python\n");
- myloop->printIndexes();
- DEBUG_PRINT("\n");
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-}
-
-static PyObject *
-chill_print_dep(PyObject *self, PyObject *args)
-{
- DEBUG_PRINT("\nC chill_print_dep()\n");
- std::cout << myloop->dep;
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-}
-
-static PyObject *
-chill_print_space(PyObject *self, PyObject *args)
-{
- DEBUG_PRINT("\nC chill_print_space()\n");
- for (int i = 0; i < myloop->stmt.size(); i++) {
- DEBUG_PRINT("s%d: ", i+1);
- Relation r;
- if (!myloop->stmt[i].xform.is_null())
- r = Composition(copy(myloop->stmt[i].xform), copy(myloop->stmt[i].IS));
- else
- r = copy(myloop->stmt[i].IS);
- r.simplify(2, 4);
- r.print();
- }
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-}
-
-static PyObject *
-chill_num_statements(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("\nC chill_num_statements() called from python\n");
- int num = myloop->stmt.size();
- //DEBUG_PRINT("C num_statement() = %d\n", num);
- return Py_BuildValue( "i", num ); // BEWARE "d" is DOUBLE, not int
-}
-
-static PyObject *
-chill_does_var_exist( PyObject *self, PyObject *args)
-{
- DEBUG_PRINT("\nC chill_does_var_exist()\n");
- int yesno = 0;
- // TODO if (myloop->symbolExists(symName)) yesno = 1;
- DEBUG_PRINT("*** chill_does_var_exist *** UNIMPLEMENTED\n");
- return Py_BuildValue( "i", yesno); // there seems to be no boolean type
-}
-
-
-static PyObject *
-chill_add_sync(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("\nC chill_add_sync() *UNTESTED*\n");
- int sstmt = -123;
- // char index_name[180];
- static char Buffer[1024];
- static char *index_name = &Buffer[0];
-
- if (!PyArg_ParseTuple(args, "is", &sstmt, &index_name)){
- fprintf(stderr, "chill_add_sync, can't parse statement number and name passed from python\n");
- exit(-1);
- }
-
- DEBUG_PRINT("chill_add_sync, statement %d index_name '%s'\n",
- sstmt, index_name);
- std::string idxName( index_name); // ??
- myloop->addSync(sstmt, idxName);
-
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-}
-
-static PyObject *
-chill_rename_index(PyObject *self, PyObject *args)
-{
- DEBUG_PRINT("\nC chill_rename_index() called from python\n");
- int sstmt;
- //char oldname[80], newname[80];
- static char old[1024], newn[1024];
-
- static char *oldname = &old[0], *newname=&newn[0];
-
- if (!PyArg_ParseTuple(args, "iss", &sstmt, &oldname, &newname)){
- fprintf(stderr, "chill_rename_index, can't parse statement number and names passed from python\n");
- exit(-1);
- }
-
- //DEBUG_PRINT("chill_rename_index, statement %d oldname '%s' newname '%s'\n",
- //sstmt, oldname, newname);
-
- std::string idxName(oldname);
- std::string newName(newname);
-
- //DEBUG_PRINT("calling myloop->renameIndex( %d, %s, %s )\n",
- //sstmt, idxName.c_str(), newName.c_str());
-
- myloop->renameIndex(sstmt, idxName, newName);
-
- //DEBUG_PRINT("after myloop->renameIndex()\n");
-
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-}
-
-
-
-//THIS NEEDS TO MOVE
-
-
-
-static PyObject *
-chill_permute_v2(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("C permute_v2()\n");
- //int tot = sizeof(args);
- //int things = tot / sizeof(PyObject *);
- //DEBUG_PRINT("tot %d bytes, %d things\n", tot, things);
-
- int sstmt = -123;
- PyObject *pyObj;
-
- //if (!PyArg_ParseTuple( args, "iO", &sstmt, &pyObj)) {
- //if (!PyArg_ParseTuple( args, "i", &sstmt)) {
- if (!PyArg_ParseTuple( args, "O", &pyObj)) { // everything on a single tuple
- fprintf(stderr, "failed to parse tuple\n");
- exit(-1);
- }
- Py_XINCREF(pyObj);
-
- // the ONLY arg is a tuple. figure out how big it is
- int tupleSize = PyTuple_Size(pyObj);
- //DEBUG_PRINT("%d things in order tuple\n", tupleSize);
-
- // first has to be the statement number
- PyObject *tupleItem = PyTuple_GetItem(pyObj, 0);
- Py_XINCREF(tupleItem);
- if (PyInt_Check( tupleItem )) sstmt = PyInt_AsLong( tupleItem );
- else {
- fflush(stdout);
- fprintf(stderr, "first tuple item in chill_permute_v2 is not an int?\n");
- exit(-1);
- }
-
- //DEBUG_PRINT("stmt %d\n", sstmt);
-
- char **strings;
- std::vector<std::string> order;
- std::string *cppstrptr;
- std::string cppstr;
-
- strings = (char **) malloc( sizeof(char *) * tupleSize ) ; // too big
- for (int i=1; i<tupleSize; i++) {
- tupleItem = PyTuple_GetItem(pyObj, i);
- Py_XINCREF(tupleItem);
- int im1 = i-1; // offset needed for the actual string vector
- if (PyString_Check( tupleItem)) {
- strings[im1] = strdup(PyString_AsString(tupleItem));
- //DEBUG_PRINT("item %d = '%s'\n", i, strings[im1]);
- //cppstrptr = new std::string( strings[im1] );
- //order.push_back( &(new std::string( strings[im1] )));
- //order.push_back( &cppstrptr );
-
- cppstr = strings[im1];
- order.push_back( cppstr );
- }
- else {
- fprintf(stderr, "later parameter was not a string?\n");
- exit(-1);
- }
-
- }
-
- myloop->permute_cuda(sstmt,order);
- //DEBUG_PRINT("returned from permute_cuda()\n");
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-}
-
-
-static PyObject *
-chill_tile_v2_3arg( PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("in chillmodule.cc, chill_tile_v2_3arg()\n");
-
- int sstmt, level, tile_size, outer_level;
- //char index_name[80], control_name[80];
- static char *index_name, *control_name;
- int tiling_method;
-
- if (!PyArg_ParseTuple(args, "iii", &sstmt, &level, &outer_level)) {
- fprintf(stderr,"chill_tile_v2, can't parse parameters passed from python\n");
- exit(-1);
- }
-
- // 3 parameter version
- //DEBUG_PRINT("chill_tile_v2( %d %d %d) (3 parameter version) \n",
- //sstmt,level,outer_level);
- myloop->tile_cuda(sstmt,level,outer_level);
- //DEBUG_PRINT("chill_tile_v2 3 parameter version returning normally\n");
- Py_RETURN_NONE;
-}
-
-
-static PyObject *
-chill_tile_v2_7arg( PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("in chillmodule.cc, chill_tile_v2_7arg()\n");
-
- int sstmt, level, tile_size, outer_level;
- //char index_name[80], control_name[80];
- static char iname[1024], cname[1024];
- static char *index_name = &iname[0], *control_name=&cname[0];
- int tiling_method;
-
- if (!PyArg_ParseTuple(args, "iiiissi",
- &sstmt, &level, &tile_size, &outer_level,
- &index_name, &control_name, &tiling_method)){
- fprintf(stderr, "chill_tile_v2_7arg, can't parse parameters passed from python\n");
- exit(-1);
- }
-
- //DEBUG_PRINT("7 parameter version was called?\n");
-
- // 7 parameter version was called
- //DEBUG_PRINT("tile_v2( %d, %d, %d, %d ... )\n",
- // sstmt, level, tile_size, outer_level);
-
- //DEBUG_PRINT("tile_v2( %d, %d, %d, %d, %s, %s, %d)\n",
- //sstmt,level,tile_size,outer_level,index_name, control_name, tiling_method);
-
- TilingMethodType method = StridedTile;
- if (tiling_method == 0) method = StridedTile;
- else if (tiling_method == 1) method = CountedTile;
- else fprintf(stderr, "ERROR: tile_v2 illegal tiling method, using StridedTile\n");
-
- //DEBUG_PRINT("outer level %d\n", outer_level);
- //DEBUG_PRINT("calling myloop->tile_cuda( %d, %d, %d, %d, %s, %s, method)\n",
- // sstmt, level, tile_size, outer_level, index_name, control_name);
-
- // BUH level+1?
- myloop->tile_cuda(sstmt, level, tile_size, outer_level, index_name, control_name, method);
- Py_RETURN_NONE;
-}
-
-
-static PyObject *
-chill_cur_indices(PyObject *self, PyObject *args)
-{
- int stmt_num = -123;
- if (!PyArg_ParseTuple(args, "i", &stmt_num)){
- fprintf(stderr, "chill_cur_indides, can't parse statement number passed from python\n");
- exit(-1);
- }
- //DEBUG_PRINT("cur_indices( %d )\n", stmt_num);
-
- char formatstring[1024];
- for (int i=0; i<1024; i++) formatstring[i] = '\0';
-
- int num = myloop->idxNames[stmt_num].size();
- for(int i=0; i<num; i++){
- //DEBUG_PRINT("myloop->idxNames[%d] index %d = '%s'\n",
- //stmt_num, i, myloop->idxNames[stmt_num][i].c_str());
-
- // backwards, works because all entries are the same
- //sprintf(formatstring, "i %s", formatstring);
- strcat( formatstring, "s ");
- // put this in a list or something to pass back to python
- }
-
- int l = strlen(formatstring);
- if (l > 0) formatstring[l-1] = '\0';
-
- //DEBUG_PRINT("%d current indices, format string '%s'\n\n",num,formatstring);
- //DEBUG_PRINT("%d current indices\n\n", num);
-
- //return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),myloop->idxNames[stmt_num][1].c_str() );
-
- // I don't know a clean way to do this.
- if (num == 2) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str());
- if (num == 3) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str());
- if (num == 4) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str());
- if (num == 5) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str());
- if (num == 6) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str());
- if (num == 7) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str());
- if (num == 8) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str());
- if (num == 9) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str());
- if (num == 10) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str(),
- myloop->idxNames[stmt_num][9].c_str());
- if (num == 11) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str(),
- myloop->idxNames[stmt_num][9].c_str(),
- myloop->idxNames[stmt_num][10].c_str());
- if (num == 12) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str(),
- myloop->idxNames[stmt_num][9].c_str(),
- myloop->idxNames[stmt_num][10].c_str(),
- myloop->idxNames[stmt_num][11].c_str());
- if (num == 13) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str(),
- myloop->idxNames[stmt_num][9].c_str(),
- myloop->idxNames[stmt_num][10].c_str(),
- myloop->idxNames[stmt_num][11].c_str(),
- myloop->idxNames[stmt_num][12].c_str());
- if (num == 14) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str(),
- myloop->idxNames[stmt_num][9].c_str(),
- myloop->idxNames[stmt_num][10].c_str(),
- myloop->idxNames[stmt_num][11].c_str(),
- myloop->idxNames[stmt_num][12].c_str(),
- myloop->idxNames[stmt_num][13].c_str());
- if (num == 15) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str(),
- myloop->idxNames[stmt_num][9].c_str(),
- myloop->idxNames[stmt_num][10].c_str(),
- myloop->idxNames[stmt_num][11].c_str(),
- myloop->idxNames[stmt_num][12].c_str(),
- myloop->idxNames[stmt_num][13].c_str(),
- myloop->idxNames[stmt_num][14].c_str());
- if (num == 16) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str(),
- myloop->idxNames[stmt_num][9].c_str(),
- myloop->idxNames[stmt_num][10].c_str(),
- myloop->idxNames[stmt_num][11].c_str(),
- myloop->idxNames[stmt_num][12].c_str(),
- myloop->idxNames[stmt_num][13].c_str(),
- myloop->idxNames[stmt_num][14].c_str(),
- myloop->idxNames[stmt_num][15].c_str());
- if (num == 17) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str(),
- myloop->idxNames[stmt_num][9].c_str(),
- myloop->idxNames[stmt_num][10].c_str(),
- myloop->idxNames[stmt_num][11].c_str(),
- myloop->idxNames[stmt_num][12].c_str(),
- myloop->idxNames[stmt_num][13].c_str(),
- myloop->idxNames[stmt_num][14].c_str(),
- myloop->idxNames[stmt_num][15].c_str(),
- myloop->idxNames[stmt_num][16].c_str());
- if (num == 18) return Py_BuildValue(formatstring, myloop->idxNames[stmt_num][0].c_str(),
- myloop->idxNames[stmt_num][1].c_str(),
- myloop->idxNames[stmt_num][2].c_str(),
- myloop->idxNames[stmt_num][3].c_str(),
- myloop->idxNames[stmt_num][4].c_str(),
- myloop->idxNames[stmt_num][5].c_str(),
- myloop->idxNames[stmt_num][6].c_str(),
- myloop->idxNames[stmt_num][7].c_str(),
- myloop->idxNames[stmt_num][8].c_str(),
- myloop->idxNames[stmt_num][9].c_str(),
- myloop->idxNames[stmt_num][10].c_str(),
- myloop->idxNames[stmt_num][11].c_str(),
- myloop->idxNames[stmt_num][12].c_str(),
- myloop->idxNames[stmt_num][13].c_str(),
- myloop->idxNames[stmt_num][14].c_str(),
- myloop->idxNames[stmt_num][15].c_str(),
- myloop->idxNames[stmt_num][16].c_str(),
- myloop->idxNames[stmt_num][17].c_str());
-
- fprintf(stderr, "going to die horribly, num=%d\n", num);
-}
-
-
-static PyObject *
-chill_block_indices(PyObject *self, PyObject *args) {
-
- // I'm unsure what the legal states are here
- // is it always "bx", or ("bx" and "by") ?
- int howmany = 0;
- char *loopnames[2];
- if (myloop->cu_bx > 1) {
- loopnames[howmany] = strdup("bx");
- howmany++;
- }
- if (myloop->cu_by > 1) {
- loopnames[howmany] = strdup("by");
- howmany++;
- }
-
- if (howmany == 0) return Py_BuildValue("()");
- if (howmany == 1) return Py_BuildValue("(s)", loopnames[0]);
- if (howmany == 2) return Py_BuildValue("(ss)", loopnames[0], loopnames[1]);
- fprintf(stderr, "chill_block_indices(), gonna die, howmany == %d", howmany);
- exit(666);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *
-chill_thread_indices(PyObject *self, PyObject *args) {
-
- // I'm unsure what the legal states are here
- // is it always "tx", or ("tx" and "ty") or ("tx" and "ty" and "tz") ?
- int howmany = 0;
- char *loopnames[3];
- if (myloop->cu_tx > 1) {
- loopnames[howmany++] = strdup("tx");
- }
- if (myloop->cu_ty > 1) {
- loopnames[howmany++] = strdup("ty");
- }
- if (myloop->cu_tz > 1) {
- loopnames[howmany++] = strdup("tz");
- }
-
- if (howmany == 0) return Py_BuildValue("()");
- if (howmany == 1) return Py_BuildValue("(s)",
- loopnames[0]);
- if (howmany == 2) return Py_BuildValue("(ss)",
- loopnames[0],
- loopnames[1]);
- if (howmany == 3) return Py_BuildValue("(sss)",
- loopnames[0],
- loopnames[1],
- loopnames[2]);
-
- fprintf(stderr, "chill_thread_indices(), gonna die, howmany == %d", howmany);
- exit(999);
-}
-
-
-
-
-
-static PyObject *
-block_dims(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("block_dims() returning %d %d\n", myloop->cu_bx, myloop->cu_by);
- Py_BuildValue( "i i", myloop->cu_bx, myloop->cu_by);
-}
-
-
-static PyObject *
-thread_dims(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("thread_dims() returning %d %d %d\n",
- //myloop->cu_tx, myloop->cu_ty, myloop->cu_tz);
-
- Py_BuildValue( "i i i", myloop->cu_tx, myloop->cu_ty, myloop->cu_tz);
-}
-
-
-static PyObject *
-chill_hard_loop_bounds(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("hard_loop_bounds(");
- int sstmt, level; // input parameters
- int upper, lower; // output
-
- if (!PyArg_ParseTuple(args, "ii", &sstmt, &level)){
- fprintf(stderr, "hard_loop_bounds, ");
- fprintf(stderr, "can't parse statement numbers passed from python\n");
- exit(-1);
- }
- //DEBUG_PRINT(" %d, %d )\n", sstmt, level);
-
- myloop->extractCudaUB(sstmt, level, upper, lower);
-
- //DEBUG_PRINT("lower %d upper %d\n", lower, upper);
-
- Py_BuildValue( "i i", lower, upper);
-}
-
-
-static PyObject *
-chill_datacopy9(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("\n\n\n***** datacopy_v2() 9ARGS\n");
-
- int sstmt;
- int level;
- std::string cppstr;
- std::string array_name;
- std::vector<std::string> new_idxs;
- bool allow_extra_read;
- int fastest_changing_dimension;
- int padding_stride;
- int padding_alignment;
- bool cuda_shared;
-
- PyObject *pyObj;
-
- if (!PyArg_ParseTuple( args, "O", &pyObj)) { // everything on a single tuple
-
- fprintf(stderr, "failed to parse tuple\n");
- exit(-1);
- }
- Py_XINCREF( pyObj );
-
- //if (PyList_Check(pyObj)) fprintf(stderr, "it's a list\n");
- //if (PyTuple_Check(pyObj)) fprintf(stderr, "it's a tuple\n");
-
-
-
- // the ONLY arg is a tuple. figure out how big it is
- int tupleSize = PyTuple_Size(pyObj);
- //DEBUG_PRINT("%d things in object tuple\n", tupleSize);
-
- // first has to be the statement number
- PyObject *tupleItem1 = PyTuple_GetItem(pyObj, 0);
- Py_INCREF(tupleItem1);
- if (PyInt_Check( tupleItem1)) sstmt = PyInt_AsLong( tupleItem1 );
- else {
- fprintf(stderr, "second tuple item in chill_datacopy9 is not an int?\n");
- exit(-1);
- }
- //DEBUG_PRINT("stmt %d\n", sstmt);
-
- PyObject *tupleItem2 = PyTuple_GetItem(pyObj, 1); // second item is level
- Py_INCREF(tupleItem2);
- if (PyInt_Check( tupleItem2 )) level = PyInt_AsLong( tupleItem2);
- else {
- fprintf(stderr, "second tuple item in chill_datacopy9 is not an int?\n");
- exit(-1);
- }
- //DEBUG_PRINT("level %d\n", level );
-
- // third item is array name
- PyObject *tupleItem3 = PyTuple_GetItem(pyObj, 2);
- Py_INCREF(tupleItem3);
- array_name = strdup(PyString_AsString(tupleItem3));
- //DEBUG_PRINT("array name '%s'\n", array_name.c_str());
-
-
- // integer number of indices
- PyObject *tupleItem4 = PyTuple_GetItem(pyObj, 3);
- Py_INCREF(tupleItem4);
- int numindex= PyInt_AsLong( tupleItem4 );
- //DEBUG_PRINT("%d indices\n", numindex);
-
-
- PyObject *tupleItemTEMP;
- for (int i=0; i<numindex; i++) {
- tupleItemTEMP = PyTuple_GetItem(pyObj, 4+i);
- Py_INCREF(tupleItemTEMP);
- cppstr = strdup(PyString_AsString(tupleItemTEMP));
- new_idxs.push_back( cppstr );
- //DEBUG_PRINT("%s\n", cppstr.c_str());
- }
-
- PyObject *tupleItem5 = PyTuple_GetItem(pyObj, 4+numindex);
- Py_INCREF(tupleItem5);
- allow_extra_read = PyInt_AsLong( tupleItem5 );
-
- PyObject *tupleItem6 = PyTuple_GetItem(pyObj, 5+numindex);
- Py_INCREF(tupleItem6);
- fastest_changing_dimension = PyInt_AsLong( tupleItem6 );
-
- PyObject *tupleItem7 = PyTuple_GetItem(pyObj, 6+numindex);
- Py_INCREF(tupleItem7);
- padding_stride = PyInt_AsLong( tupleItem7 );
-
- PyObject *tupleItem8 = PyTuple_GetItem(pyObj, 7+numindex);
- Py_INCREF(tupleItem8);
- padding_alignment = PyInt_AsLong( tupleItem8 );
-
- PyObject *tupleItem9 = PyTuple_GetItem(pyObj, 8+numindex);
- Py_INCREF(tupleItem9);
- cuda_shared = PyInt_AsLong( tupleItem9 );
-
-
- //DEBUG_PRINT("calling myloop->datacopy_cuda()\n");
-
- // corruption happenes in here???
- myloop->datacopy_cuda(sstmt, level, array_name, new_idxs,
- allow_extra_read, fastest_changing_dimension,
- padding_stride, padding_alignment, cuda_shared);
-
- DEBUG_PRINT("before attempt (after actual datacopy)\n");
- //myloop->printCode(); // attempt to debug
- DEBUG_PRINT("back from attempt\n");
-
- //DEBUG_PRINT("datacopy_9args returning\n");
-
- Py_RETURN_NONE;
-}
-
-
-
-
-
-static PyObject *
-chill_datacopy_privatized(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("C datacopy_privatized\n");
- PyObject *pyObj;
- if (!PyArg_ParseTuple( args, "O", &pyObj)) { // everything on a single tuple
- fprintf(stderr, "failed to parse tuple\n");
- exit(-1);
- }
-
- PyObject *tupleItem = PyTuple_GetItem(pyObj, 0); // statement number
- Py_XINCREF(tupleItem);
- int sstmt = PyInt_AsLong( tupleItem );
-
- tupleItem = PyTuple_GetItem(pyObj, 1); // start_loop
- Py_XINCREF(tupleItem);
- std::string start_loop = strdup(PyString_AsString(tupleItem));
- int level = myloop->findCurLevel(sstmt, start_loop);
-
-
- tupleItem = PyTuple_GetItem(pyObj, 2); // array_name
- Py_XINCREF(tupleItem);
- std::string array_name = strdup(PyString_AsString(tupleItem));
-
- // things to hold constant - first a count, then the things
- tupleItem = PyTuple_GetItem(pyObj, 3); // how many things in the array
- Py_XINCREF(tupleItem);
- int howmany = PyInt_AsLong( tupleItem );
-
- //DEBUG_PRINT("%d things to hold constant: ", howmany);
- std::vector<std::string> holdconstant;
- std::string cppstr;
-
- for (int i=0; i<howmany; i++) {
- tupleItem = PyTuple_GetItem(pyObj, 4+i);
- Py_XINCREF(tupleItem);
- cppstr = strdup(PyString_AsString(tupleItem));
- holdconstant.push_back( cppstr ); // add at end
- }
-
- std::vector<int> privatized_levels(howmany);
- for(int i=0; i<howmany; i++) {
- privatized_levels[i] = myloop->findCurLevel(sstmt, holdconstant[i]);
- //DEBUG_PRINT("privatized_levels[ %d ] = %d\n", i, privatized_levels[i] );
- }
-
- bool allow_extra_read = false;
- int fastest_changing_dimension = -1;
- int padding_stride = 1;
- int padding_alignment = 1;
- bool cuda_shared = false;
-
-
- myloop->datacopy_privatized_cuda(sstmt, level, array_name, privatized_levels,
- allow_extra_read, fastest_changing_dimension,
- padding_stride, padding_alignment,
- cuda_shared);
-
-
- Py_RETURN_NONE;
-}
-
-
-
-
-
-
-static PyObject *
-chill_unroll(PyObject *self, PyObject *args)
-{
- int sstmt, level, unroll_amount;
-
- if (!PyArg_ParseTuple(args, "iii", &sstmt, &level, &unroll_amount)) {
- fprintf(stderr, "chill_unroll, can't parse parameters passed from python\n");
- exit(-1);
- }
-
- //DEBUG_PRINT("chill_unroll( %d, %d, %d)\n", sstmt, level, unroll_amount );
- bool does_expand = myloop->unroll_cuda(sstmt,level,unroll_amount);
-
- // TODO return the boolean?
- Py_RETURN_NONE;
-}
-
-
-
-
-static PyObject *
-chill_cudaize_v2(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("cudaize_v2\n");
- PyObject *pyObj;
- if (!PyArg_ParseTuple( args, "O", &pyObj)) { // everything on a single tuple
- fprintf(stderr, "failed to parse tuple\n");
- exit(-1);
- }
-
- // the ONLY arg is a tuple. figure out how big it is
- int tupleSize = PyTuple_Size(pyObj);
- //DEBUG_PRINT("%d things in tuple\n", tupleSize);
-
- PyObject *tupleItem = PyTuple_GetItem(pyObj, 0); //the kernel name
- Py_XINCREF(tupleItem);
- std::string kernel_name = strdup(PyString_AsString(tupleItem));
-
- std::map<std::string, int> array_sizes;
- tupleItem = PyTuple_GetItem(pyObj, 1); // number of array sizes
- Py_XINCREF(tupleItem);
- int numarraysizes = PyInt_AsLong( tupleItem );
-
- std::string cppstr;
- int offset = 2;
- for (int i=0; i<numarraysizes; i++) {
- tupleItem = PyTuple_GetItem(pyObj, offset++);
- Py_XINCREF(tupleItem);
- cppstr = strdup(PyString_AsString(tupleItem));
- tupleItem = PyTuple_GetItem(pyObj, offset++); // integer size
- int siz = PyInt_AsLong( tupleItem );
-
- //DEBUG_PRINT("arraysize for %s = %d\n", cppstr.c_str(), siz);
- array_sizes.insert( std::make_pair( cppstr, siz ));
- }
-
-
- std::vector<std::string> blockIdxs;
- tupleItem = PyTuple_GetItem(pyObj, offset++); // integer number of blocks
- Py_XINCREF(tupleItem);
- int numblocks = PyInt_AsLong( tupleItem );
- //DEBUG_PRINT("%d blocks\n", numblocks);
- for (int i=0; i<numblocks; i++) {
- tupleItem = PyTuple_GetItem(pyObj, offset++);
- cppstr = strdup(PyString_AsString(tupleItem));
- blockIdxs.push_back( cppstr );
- //DEBUG_PRINT("%s\n", cppstr.c_str());
- }
-
- std::vector<std::string> threadIdxs;
- tupleItem = PyTuple_GetItem(pyObj, offset++); // integer number of threads
- Py_XINCREF(tupleItem);
- int numthreads= PyInt_AsLong( tupleItem );
- //DEBUG_PRINT("%d threads\n", numthreads);
- for (int i=0; i<numthreads; i++) {
- tupleItem = PyTuple_GetItem(pyObj, offset++);
- Py_XINCREF(tupleItem);
- cppstr = strdup(PyString_AsString(tupleItem));
- threadIdxs.push_back( cppstr );
- //DEBUG_PRINT("%s\n", cppstr.c_str());
- }
-
-
- myloop->cudaize_v2(kernel_name, array_sizes, blockIdxs, threadIdxs);
-
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-}
-
-
-
-static PyObject *get_loop_num() {
- // TODO get_loop_num() it's a global value?
- fprintf(stderr, "get_loop_num() UNIMPLEMENTED\n");
- exit(-1);
-}
-
-
-
-
-static PyObject *
-chill_copy_to_texture(PyObject *self, PyObject *args)
-{
- //DEBUG_PRINT("C copy_to_texture() called from python \n");
- const char *array_name;
- if (!PyArg_ParseTuple(args, "s", &array_name)){
- fprintf(stderr, "chill_copy_to_texture can't parse array name\n");
- exit(-1);
- }
- //DEBUG_PRINT("array name = %s\n", array_name);
- myloop->copy_to_texture(array_name);
-
- Py_RETURN_NONE;
-}
-
-
-
-
-
-
-
-static PyObject *
-chill_init(PyObject *self, PyObject *args)
-{
- DEBUG_PRINT("C chill_init() called from python as read_IR()\n");
- DEBUG_PRINT("C init( ");
- const char *filename;
- const char *procname;
- if (!PyArg_ParseTuple(args, "ss", &filename, &procname)){
- fprintf(stderr, "umwut? can't parse file name and procedure name?\n");
- exit(-1);
- }
-
- int loop_num = 0;
-
- DEBUG_PRINT("%s, 0, 0 )\n", filename);
-
- DEBUG_PRINT("GETTING IR CODE in chill_init() in chillmodule.cc\n");
- DEBUG_PRINT("ir_code = new IR_cudaroseCode(%s, %s);\n",filename, procname);
- ir_code = new IR_cudaroseCode(filename, procname); //this produces 15000 lines of output
- fflush(stdout);
-
-
-
-
- //protonu--here goes my initializations
- //A lot of this code was lifted from Chun's parser.yy
- //the plan is now to create the LoopCuda object directly
- IR_Block *block = ir_code->GetCode();
- DEBUG_PRINT("ir_code->FindOneLevelControlStructure(block); chillmodule.cc\n");
- ir_controls = ir_code->FindOneLevelControlStructure(block);
-
- int loop_count = 0;
- for (int i = 0; i < ir_controls.size(); i++) {
- if (ir_controls[i]->type() == IR_CONTROL_LOOP) {
- loops.push_back(i);
- loop_count++;
- }
- }
- delete block;
-
-
- std::vector<IR_Control *> parm;
- for(int j = 0; j < loop_count; j++)
- parm.push_back(ir_controls[loops[j]]);
-
-
- DEBUG_PRINT("block = ir_code->MergeNeighboringControlStructures(parm);\n");
- block = ir_code->MergeNeighboringControlStructures(parm);
-
- //DEBUG_PRINT("myloop = new LoopCuda(block, loop_num); in chillmodule.cc\n");
- myloop = new LoopCuda(block, loop_num);
- fflush(stdout); DEBUG_PRINT("back\n");
- delete block;
-
- //end-protonu
-
- fflush(stdout);
- DEBUG_PRINT("myloop->original();\n");
- myloop->original();
- fflush(stdout);
- DEBUG_PRINT("myloop->useIdxNames=true;\n");
- myloop->useIdxNames=true;//Use idxName in code_gen
- //register_v2(L);
-
- fflush(stdout);
- DEBUG_PRINT("chill_init DONE\n");
- Py_RETURN_NONE; // return Py_BuildValue( "" );
-
-}
-
-#else
// ------------------------- //
// CHiLL interface functions //
// ------------------------- //
@@ -1737,42 +740,7 @@ chill_num_statements(PyObject *self, PyObject *args)
//DEBUG_PRINT("C num_statement() = %d\n", num);
return Py_BuildValue( "i", num ); // BEWARE "d" is DOUBLE, not int
}
-#endif
-#ifdef CUDACHILL
-static PyMethodDef ChillMethods[] = {
-
- // python name C routine parameter passing comment
- {"print_code", chill_print_code, METH_VARARGS, "print the code at this point"},
- {"print_ri", chill_print_ri , METH_VARARGS, "print Runtime Info "},
- {"print_idx", chill_print_idx , METH_VARARGS, "print indices "},
- {"print_dep", chill_print_dep , METH_VARARGS, "print dep, dependecies?"},
- {"print_space", chill_print_space, METH_VARARGS, "print something or other "},
- {"add_sync", chill_add_sync, METH_VARARGS, "add sync, whatever that is"},
- {"rename_index", chill_rename_index, METH_VARARGS, "rename a loop index"},
- {"permute", chill_permute, METH_VARARGS, "change the order of loops?"},
- {"tile3", chill_tile_v2_3arg, METH_VARARGS, "something to do with tile"},
- {"tile7", chill_tile_v2_7arg, METH_VARARGS, "something to do with tile"},
- {"thread_dims", thread_dims, METH_VARARGS, "tx, ty, tz "},
- {"block_dims", block_dims, METH_VARARGS, "bx, by"},
- {"thread_indices", chill_thread_indices, METH_VARARGS, "bx, by"},
- {"block_indices", chill_block_indices, METH_VARARGS, "bx, by"},
- {"hard_loop_bounds", chill_hard_loop_bounds, METH_VARARGS, "lower, upper"},
- {"unroll", chill_unroll, METH_VARARGS, "unroll a loop"},
- {"cudaize", chill_cudaize_v2, METH_VARARGS, "dunno"},
- {"datacopy_privatized", chill_datacopy_privatized, METH_VARARGS, "dunno"},
-
- {"datacopy_9arg", chill_datacopy9, METH_VARARGS, "datacopy with 9 arguments"},
- {"copy_to_texture", chill_copy_to_texture, METH_VARARGS, "copy to texture mem"},
- {"read_IR", chill_init, METH_VARARGS, "read an Intermediate Representation file"},
- {"cur_indices", chill_cur_indices, METH_VARARGS, "currently active indices"},
- {"num_statements", chill_num_statements, METH_VARARGS, "number of statements in ... something"},
- {NULL, NULL, 0, NULL} /* Sentinel */
-
- //{"copy_to_constant", chill_copy_to_constant, METH_VARARGS, "copy to constant mem"},
-
-};
-#else
static PyMethodDef ChillMethods[] = {
//python name C routine parameter passing comment
@@ -1807,7 +775,6 @@ static PyMethodDef ChillMethods[] = {
{"num_statements", chill_num_statements, METH_VARARGS, "number of statements in the current loop"},
{NULL, NULL, 0, NULL}
};
-#endif
static void register_globals(PyObject* m) {
// Preset globals