示例#1
0
文件: object.cpp 项目: ngaloppo/isaac
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;
}
示例#2
0
Couple::Couple(string key, const tuple &tuple)
    :key(key)
{
    for(int i = 0; i < tuple.size(); i++) {
        values.push_back(tuple[i].c_str());
    }
}
示例#3
0
文件: object.cpp 项目: ngaloppo/isaac
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);
}