Loop Transform using ISL

2 views
Skip to first unread message

Man Xavier

unread,
Nov 12, 2025, 2:31:34 PMNov 12
to isl Development
I'm new to ISL.
I'm trying to Transform AST
for r in range(10)
    for p in range(10)
        S0: A1[0,p] = max(A1[0,p], A0[r,p])
for r in range(10)
    for p in range(10)
        S1: A2[r,p] = A0[r,p] - A1[0,p]
TO AST
for p in range(10)
    for r in range(10)
        S0: A1[0,p] = max(A1[0,p], A0[r,p])
    for r in range(10)
        S1: A2[r,p] = A0[r,p] - A1[0,p]
I use the following code to realize the function:
  1. import isl

  2. context = isl.set("{ : }")

  3. schedule_space = isl.set("{[t0,t1,t2]:}").get_space()
  4. precedes = isl.map.lex_lt(schedule_space)

  5. # iteration domain
  6. domain = isl.union_set(" {S0[i,j] : 0<=i<10 and 0<=j<10; S1[i,j] : 0<=i<10 and 0<=j<10; }")

  7. schedule = isl.union_map("{S0[i,j] -> [t0,t1,t2] : t0 = 1 and t1 = i and t2 = j; S1[i,j] -> [t0,t1,t2] : t0 = 2 and  t1 = i and t2 = j}")

  8. build = isl.ast_build.from_context(context)
  9. ast = build.node_from_schedule_map(schedule.intersect_domain(domain))
  10. print(ast.to_C_str())

  11. reads = isl.union_map("{S0[i,j] -> A0[a=i,b=j]; S0[i,j] -> A1[a=0,b=j];S1[i,j] -> A1[a=0,b=j];}")
  12. reads= reads.intersect_domain(domain)

  13. writes = isl.union_map("{S0[i,j] -> A1[a=0,b=j]; S1[i,j] -> A2[a=i,b=j]; S[j] -> A1[0,b=j]}")
  14. writes= writes.intersect_domain(domain)

  15. raw = writes.apply_range(reads.reverse())
  16. raw = raw.apply_domain(schedule).apply_range(schedule)
  17. raw = raw.intersect(precedes)
  18. raw = raw.apply_domain(schedule.reverse()).apply_range(schedule.reverse())


  19. war = reads.apply_range(writes.reverse())
  20. war = war.apply_domain(schedule).apply_range(schedule)
  21. war = war.intersect(precedes)
  22. war = war.apply_domain(schedule.reverse()).apply_range(schedule.reverse())


  23. waw = writes.apply_range(writes.reverse())
  24. waw = waw.apply_domain(schedule).apply_range(schedule)
  25. waw = waw.intersect(precedes)
  26. waw = waw.apply_domain(schedule.reverse()).apply_range(schedule.reverse())


  27. sc = isl.schedule_constraints.on_domain(domain)
  28. dep = war.union(raw).union(waw)

  29. sc = sc.set_validity(dep)
  30. sc = sc.set_proximity(dep)
  31. sched = sc.compute_schedule()
  32. build = isl.ast_build.from_context(context)
  33. ast = build.node_from(sched)
  34. print(ast.to_C_str())
The experimental result is that: WITHOUT line 18 and line 21, I can get the expected AST. 
WITH line 18 and line 21, I can just get the following AST:
  for (int c0 = 0; c0 <= 9; c0 += 1)
    for (int c1 = 0; c1 <= 9; c1 += 1)
      S0(c1, c0);
  for (int c0 = 0; c0 <= 9; c0 += 1)
    for (int c1 = 0; c1 <= 9; c1 += 1)
      S1(c0, c1);
Why does this happen? What is the correct way to realize the transformation?

Reply all
Reply to author
Forward
0 new messages