Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime dynamic size array/list/vector of arbitrary type in callable/kernel #96

Closed
MaxwellFang opened this issue Nov 3, 2023 · 2 comments

Comments

@MaxwellFang
Copy link

MaxwellFang commented Nov 3, 2023

Is your feature request related to a problem? Please describe.
I want to record all the vertex in the path. The vertex is a struct which consists of all DSL variables. However I didn't find a good way to record that in the callable as it seems like the size and the index should be determined at "compile time". Is there any suggested way of doing that?

Describe the solution you'd like

Array<Vertex> vertices(n);
...
$for(i, max_depth) {
    auto v = vertices[i];
    v.position = make_float3(1.0f);
}
...

Describe alternatives you've considered
I have tried linked list by using a pointer in Vertex, but this does not seem right as DSL have not actually run the code. Any suggestion on how to properly implement that will also be helpful.

@Mike-Leo-Smith
Copy link
Contributor

Hi, @MaxwellFang

You may use Local<T> in <luisa/dsl/local.h> which can be constructed with runtime-specified lengths. The element type T can be any DSL type, i.e., scalars, vectors, matrices, or POD structures reflected by LUISA_STRUCT.

Example:

namespace some {
struct Test {
  float a;
  uint2 b;
};
} // namespace some

// reflect the plain C structure
LUISA_STRUCT(some::Test, a, b) {};

int main() {
  uint n = some_runtime_value();
  Kernel1D kernel = [] {
    Local<Test> x{n}; // construct an array with n elements of struct Test
  };
}

@MaxwellFang
Copy link
Author

Hi, @MaxwellFang

You may use Local<T> in <luisa/dsl/local.h> which can be constructed with runtime-specified lengths. The element type T can be any DSL type, i.e., scalars, vectors, matrices, or POD structures reflected by LUISA_STRUCT.

Example:

namespace some {
struct Test {
  float a;
  uint2 b;
};
} // namespace some

// reflect the plain C structure
LUISA_STRUCT(some::Test, a, b) {};

int main() {
  uint n = some_runtime_value();
  Kernel1D kernel = [] {
    Local<Test> x{n}; // construct an array with n elements of struct Test
  };
}

My struct is something like

struct Vertex {
    Float3 position;
    SampledSpectrum beta;
    ....
};

which the variables DSL types but the struct itself is not reflected by LUISA_STRUCT. So I was wondering if that would be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants