Class: Barracuda::Buffer
Direct Known Subclasses
Instance Method Summary collapse
- #data ⇒ Object
- #data=(new_value) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #read ⇒ Object
- #size_changed ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'ext/barracuda.c', line 374 static VALUE buffer_initialize(int argc, VALUE *argv, VALUE self) { if (argc == 0) { rb_raise(rb_eArgError, "no buffer data given"); } if (TYPE(argv[0]) == T_ARRAY) { buffer_data_set(self, argv[0]); } else { buffer_data_set(self, rb_ary_new4(argc, argv)); } return self; } |
Instance Method Details
#data ⇒ Object
354 355 356 357 358 359 |
# File 'ext/barracuda.c', line 354 static VALUE buffer_data(VALUE self) { GET_BUFFER(); return buffer->arr; } |
#data=(new_value) ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'ext/barracuda.c', line 361 static VALUE buffer_data_set(VALUE self, VALUE new_value) { GET_BUFFER(); if (RTEST(buffer->arr)) { rb_gc_mark(buffer->arr); } buffer->arr = new_value; buffer_size_changed(self); return buffer->arr; } |
#read ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'ext/barracuda.c', line 319 static VALUE buffer_read(VALUE self) { unsigned int i, index; GET_BUFFER(); rb_gc_mark(buffer->arr); buffer->arr = rb_ary_new2(buffer->num_items); for (i = 0, index = 0; i < buffer->num_items; i++, index += buffer->member_size) { VALUE value = type_to_ruby(((int8_t*)buffer->cachebuf) + index, buffer->type); rb_ary_push(buffer->arr, value); } return self; } |
#size_changed ⇒ Object
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'ext/barracuda.c', line 337 static VALUE buffer_size_changed(VALUE self) { GET_BUFFER(); if (buffer->data) { clReleaseMemObject(buffer->data); } buffer_update_cache_info(buffer); buffer->data = clCreateBuffer(context, CL_MEM_READ_WRITE, buffer->num_items * buffer->member_size, NULL, NULL); buffer_write(self); return self; } |
#write ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'ext/barracuda.c', line 294 static VALUE buffer_write(VALUE self) { unsigned int i, index; unsigned long data_ptr[16]; // data buffer GET_BUFFER(); buffer_update_cache_info(buffer); if (buffer->cachebuf) { xfree(buffer->cachebuf); } buffer->cachebuf = malloc(buffer->num_items * buffer->member_size); for (i = 0, index = 0; i < RARRAY_LEN(buffer->arr); i++, index += buffer->member_size) { VALUE item = RARRAY_PTR(buffer->arr)[i]; type_to_native(item, buffer->type, (void *)data_ptr); memcpy(((int8_t*)buffer->cachebuf) + index, (void *)data_ptr, buffer->member_size); } return self; } |