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

Update module.h #563

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
93 changes: 27 additions & 66 deletions include/taco/codegen/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <utility>
#include <random>
#include <sstream>

#include "taco/target.h"
#include "taco/ir/ir.h"
Expand All @@ -15,78 +16,38 @@ namespace ir {

class Module {
public:
/// Create a module for some target
Module(Target target=getTargetFromEnvironment())
: lib_handle(nullptr), moduleFromUserSource(false), target(target) {
setJITLibname();
setJITTmpdir();
}
Module(Target target = getTargetFromEnvironment());

/// Compile the source into a library, returning its full path
std::string compile();

/// Compile the module into a source file located at the specified location
/// path and prefix. The generated source will be path/prefix.{.c|.bc, .h}
void compileToSource(std::string path, std::string prefix);

/// Compile the module into a static library located at the specified location
/// path and prefix. The generated library will be path/prefix.a
void compileToStaticLibrary(std::string path, std::string prefix);

/// Add a lowered function to this module */
void addFunction(Stmt func);
std::string compile();
void compileToSource(std::string path, std::string prefix);
void compileToStaticLibrary(std::string path, std::string prefix);
void addFunction(Stmt func);
std::string getSource();
void* getFuncPtr(std::string name);
int callFuncPackedRaw(std::string name, std::vector<void*> args);
int callFuncPacked(std::string name, std::vector<void*> args);

/// Get the source of the module as a string */
std::string getSource();

/// Get a function pointer to a compiled function. This returns a void*
/// pointer, which the caller is required to cast to the correct function type
/// before calling. If there's no function of this name then a nullptr is
/// returned.
void* getFuncPtr(std::string name);
void setSource(std::string source);

/// Call a raw function in this module and return the result
int callFuncPackedRaw(std::string name, void** args);

/// Call a raw function in this module and return the result
int callFuncPackedRaw(std::string name, std::vector<void*> args) {
return callFuncPackedRaw(name, args.data());
}

/// Call a function using the taco_tensor_t interface and return the result
int callFuncPacked(std::string name, void** args) {
return callFuncPackedRaw("_shim_"+name, args);
}

/// Call a function using the taco_tensor_t interface and return the result
int callFuncPacked(std::string name, std::vector<void*> args) {
return callFuncPacked(name, args.data());
}

/// Set the source of the module
void setSource(std::string source);

private:
std::stringstream source;
std::stringstream header;
std::string libname;
std::string tmpdir;
void* lib_handle;
std::vector<Stmt> funcs;

// true iff the module was created from user-provided source
bool moduleFromUserSource;

Target target;

void setJITLibname();
void setJITTmpdir();

static std::string chars;
static std::default_random_engine gen;
static std::uniform_int_distribution<int> randint;
std::stringstream source;
std::stringstream header;
std::string libname;
std::string tmpdir;
void* lib_handle;
std::vector<Stmt> funcs;
bool moduleFromUserSource;
Target target;

static std::string chars;
static std::default_random_engine gen;
static std::uniform_int_distribution<int> randint;

void setJITLibname();
void setJITTmpdir();
};

} // namespace ir
} // namespace taco

#endif