bool add(key_t key, const add_t &val, val_t *_oval = 0) { bits_t oval = data[key]; val_t nval = val_t(oval) + val; while(true) { bits_t noval = atomic.cas(&data[key], oval, nval.bits()); if(noval == oval) { if(_oval) *_oval = oval; return true; } oval = noval; nval = val_t(oval) + val; } return true; }
static void get(backend::source_generator &src, const ccsr_product<val_t, col_t, idx_t, T>&, const backend::command_queue&, const std::string &prm_name, detail::kernel_generator_state_ptr) { typedef decltype(val_t() * T()) res_t; src.function<res_t>(prm_name + "_spmv") .open("(") .template parameter< global_ptr<const idx_t> >("idx") .template parameter< global_ptr<const idx_t> >("row") .template parameter< global_ptr<const col_t> >("col") .template parameter< global_ptr<const val_t> >("val") .template parameter< global_ptr<const T> >("vec") .template parameter< size_t >("i") .close(")").open("{"); src.new_line() << type_name<res_t>() << " sum = 0;"; src.new_line() << "for(size_t pos = idx[i], j = row[pos], end = row[pos+1]; j < end; ++j)"; src.open("{"); src.new_line() << "sum += val[j] * vec[i + col[j]];"; src.close("}"); src.new_line() << "return sum;"; src.close("}"); }
val_t get_val() const { return val_t(val); }