Skip to content

Help speeding up a loop operation #340

Answered by Speierers
asprasan asked this question in Q&A
Discussion options

You must be logged in to vote

Instead of using a for loop, you should be able to compute all the distances to all the centers at once using a larger wavefront size and then accumulate all the height values using a dr.scatter_reduce operation. This would be very fast to compile for Dr.Jit (in forward and backward) and scale better as the number of elements increases.

Something like this (un-tested!):

obj_vertices = dr.unravel(mi.Vector3f, params['object.vertex_positions'])

num_vertices = dr.width(obj_vertices)
size = num_elems * num_vertices

centers = dr.repeat(mi.Point2f(center_x_values, center_y_values), num_vertices)
dist = dr.sqrt(dr.sum(dr.sqr(mi.Point2f(obj_vertices.x, obj_vertices.y) - centers)))

new_height = g…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by asprasan
Comment options

You must be logged in to vote
2 replies
@Speierers
Comment options

@asprasan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants