Column-Major 형식 배열 파이어 배열에 선형화 된 STL 펜던트 인 stl::array<float, 24> foo
이 있다고 가정합니다. af::array bar = af::array(4,3,2, 1, f32);
. 그래서 나는 객체 dims
의 크기가 bar
이고, 최대 4 개는 af::seq
이고 객체는 선형 배열 foo
입니다.arrayfire에서 선형 인덱스를 명시 적으로 가져 오는 방법은 무엇입니까?
foo
(예 : bar
의 선형화 된 버전)의 색인을 명시 적으로 가져 오는 것이 가능한가요? 2.nd 및 3.rd 행 (예 : bar(af::seq(1,2), af::span, af::span, af::span)
? 아래에 주어진 작은 코드 예제를 통해 원하는 것을 보여줍니다. 결국 나는 내가 왜 이것을 원하는지 설명한다.
af::dim4 bigDims = af::dim4(4,3,2);
stl::array<float, 24> foo; // Resides in RAM and is big
float* selBuffer_ptr; // Necessary for AF correct type autodetection
stl::vector<float> selBuffer;
// Load some data into foo
af::array selection; // Resides in VRAM and is small
af::seq selRows = af::seq(1,2);
af::seq selCols = af::seq(bigDims[1]); // Emulates af::span
af::seq selSlices = af::seq(bigDims[2]); // Emulates af::span
af::dim4 selDims = af::dim4(selRows.size, selCols.size, selSlices.size);
dim_t* linIndices;
// Magic functionality getting linear indices of the selection
// selRows x selCols x selSlices
// Assign all indexed elements to a consecutive memory region in selBuffer
// I know their positions within the full dataset, b/c I know the selection ranges.
selBuffer_ptr = static_cast<float> &(selBuffer[0]);
selection = af::array(selDims, selBuffer_ptr); // Copies just the selection to the device (e.g. GPU)
// Do sth. with selection and be happy
// I don't need to write back into the foo array.
는 Arrayfire 요소에 액세스하기 위해 구현 된 이러한 논리를 가지고 있어야하고 나는 그런 af::index, af::seqToDims, af::gen_indexing, af::array::operator()
같은 여러 관련 클래스/함수 발견 - 나는 아직 밖으로 쉬운 방법을 알 수없는 그러나 있습니다.
기본적으로 operator()
을 다시 구현한다고 생각 했으므로 유사하게 작동하지만 배열 객체에 대한 참조는 필요하지 않습니다. 그러나 어레이 파이어 프레임 워크에서 쉬운 방법이 있다면 이것은 낭비 될 수 있습니다.
배경 : arrayfire는 GPU 백엔드에 링크되는 동안 만 메인 메모리 (CPU 컨텍스트)에 데이터를 저장하는 것을 허용하지 않기 때문에 내가 그렇게 할 이유입니다. 필자는 많은 양의 데이터를 처리해야하고 VRAM은 매우 제한적이므로 항상 주 메모리에있는 stl-container에서 ad-hoc을 af::array
인스턴스로 인스턴스화하고 싶습니다.
물론 나는 내 문제를 해결하기 위해 일부 색인 마법을 프로그램 할 수 있지만 꽤 복잡한 색인 구조를 효율적으로 구현할 수있는 매우 복잡한 af::seq
개체를 사용하고 싶습니다.
선형 인덱스가이 경우에 도움이되는 이유는 무엇입니까? 선형 인덱스를 얻은 후에해야 할 일에 대해 몇 가지 코드를 표시하면 좋을 것입니다. –