public CArray(int n, EType type, EMemorySpace side, CModel model, string name) { alloc(n, type, side, model); _model = model; _suballocated = false; _number_of_internal_buffers = 0; _internal_buffer_pointers = null; _name = name; }
public CArray(CArray buf, uint offset_in_bytes, int sz, CModel model, string name) { if (buf == null) throw new System.Exception(); if (sz > buf._sz - offset_in_bytes) throw new System.Exception(); this._ptr = buf._ptr + offset_in_bytes; this._length = 0; this._sz = sz; this._side = buf._side; _model = model; _suballocated = false; _number_of_internal_buffers = 0; _internal_buffer_pointers = null; _name = name; }
private void alloc(int n, EType type, EMemorySpace side, CModel model) { if (n == 0) return; if (_model == null) { _model = model; } else { if (_model != model) throw new System.Exception(); } this._type = type; this._side = side; if (_sz == 0) { if (side == EMemorySpace.device) { if (_suballocated) throw new System.Exception(); _ptr = opcuda_mem_alloc((uint)(Size_of_one * n)); } else { if (_suballocated) throw new System.Exception(); _hptr = opcuda_mem_alloc_host((uint)(Size_of_one * n)); } int status = opcuda_get_status(); if (status != 0) throw new System.Exception(); _length = n; _sz = Size_of_one * n; return; } if (_sz < Size_of_one * n) { if (side == EMemorySpace.device) { if (_suballocated) throw new System.Exception(); opcuda_mem_free_device(ptr); _ptr = opcuda_mem_alloc((uint)(Size_of_one * n)); } else { if (_suballocated) throw new System.Exception(); opcuda_mem_free_host(hptr); _hptr = opcuda_mem_alloc_host((uint)(Size_of_one * n)); } int status = opcuda_get_status(); if (status != 0) throw new System.Exception(); _sz = Size_of_one * n; _length = n; return; } _length = n; }
public static void suballoc(ref CArray target, CArray buf, int n, EType type, EMemorySpace side, string name) { if (target != null) throw new System.Exception(); if (buf._internal_buffer_pointers == null) { buf._internal_buffer_pointers = new int[1000]; for (int i = 0; i < 1000; i++) { buf._internal_buffer_pointers[i] = -1; } } if (buf._internal_buffer_names == null) { buf._internal_buffer_names = new string[1000]; for (int i = 0; i < 1000; i++) { buf._internal_buffer_names[i] = null; } } if (buf == null) throw new System.Exception(); target = new CArray(buf.model); target._sz = round(n, type) * sizeof_type(type); if (buf.sz < buf._offset + target._sz) throw new System.Exception(); target._suballocated = true; target._ptr = (uint)(buf._ptr + buf._offset); target._name = name; buf._internal_buffer_pointers[buf._number_of_internal_buffers] = (int)target._ptr; buf._internal_buffer_names[buf._number_of_internal_buffers] = target._name; buf._number_of_internal_buffers += 1; target._side = side; target._type = type; target._length = n; target._name = name; buf._offset += target._sz; if (target.ptr - (target.ptr / 128) * 128 > 0) throw new System.Exception(); }
public static void alloc(ref CArray buf, int n, EType type, EMemorySpace side, CModel model, string name) { if (buf == null) { buf = new CArray(n, type, side, model, name); return; } if (buf._suballocated) throw new System.Exception(); if (buf.sz < n * sizeof_type(type)) { if (model != buf._model) throw new System.Exception(); buf = new CArray(n, type, side, model, name); return; } if (model != buf._model) throw new System.Exception(); }