std::string array::make_broadcast(const tuple &shape) { std::string result = "at("; for(size_t i = 0 ; i < shape.size() ; ++i) result += ((result.back()=='(')?"arg":",arg") + tools::to_string(i); result += ") : at("; for(size_t i = 0 ; i < shape.size() ; ++i) if(shape[i] > 1) result += ((result.back()=='(')?"arg":",arg") + tools::to_string(i); result += ")"; return result; }
Couple::Couple(string key, const tuple &tuple) :key(key) { for(int i = 0; i < tuple.size(); i++) { values.push_back(tuple[i].c_str()); } }
buffer::buffer(driver::Context const & context, std::string const & scalartype, unsigned int id, const tuple &shape, tuple const & strides) : array(context, scalartype, id), dim_(numgt1(shape)) { //Attributes attributes_["off"] = process("#name_off"); for(unsigned int i = 0 ; i < dim_ ; ++i){ std::string inc = "inc" + tools::to_string(i); attributes_[inc] = process("#name_" + inc); } //Access std::vector<std::string> args; for(unsigned int i = 0 ; i < dim_ ; ++i) args.push_back("x" + tools::to_string(i)); std::string off = "#off"; for(unsigned int i = 0 ; i < dim_ ; ++i) { std::string inc = "#inc" + tools::to_string(i); off += " + (" + args[i] + ")*" + inc; } macros_.insert("at(" + tools::join(args, ",") + "): #pointer[" + off + "]"); //Broadcast if(numgt1(shape)==0) macros_.insert("at(i): at()"); if(dim_!=shape.size()) macros_.insert(make_broadcast(shape)); add_base("buffer"); add_load(strides[0]==1 && shape[0]>1); }