-
Notifications
You must be signed in to change notification settings - Fork 13
New cyfra core #53
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
Merged
Merged
New cyfra core #53
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
72f453c
Init work on new cyfra
szymon-rd 6182ee0
Scaffold ready
szymon-rd 58e7893
Some formatting
szymon-rd d3a2878
Added Execution Result
szymon-rd f52c785
Construction works in progress
szymon-rd 79b5339
another version
szymon-rd 6a5d414
More review fixes.
szymon-rd 9d3b21e
Rename package
szymon-rd 393f397
Make ExecLayout invariant
szymon-rd 953de86
allocation fixes
szymon-rd 9857cfa
more fixes
szymon-rd 5572730
changed program
szymon-rd cf8aec8
ignore redunctant cast
MarconZet 49bc9ab
fmt
szymon-rd 89f1761
fixed sth
MarconZet 601d8a3
LF!
szymon-rd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
cyfra-core/src/main/scala/io/computenode/cyfra/core/Allocation.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package io.computenode.cyfra.core | ||
|
|
||
| import io.computenode.cyfra.core.layout.{Layout, LayoutStruct} | ||
| import io.computenode.cyfra.dsl.Value | ||
| import io.computenode.cyfra.dsl.Value.FromExpr | ||
| import io.computenode.cyfra.dsl.binding.{GBinding, GBuffer, GUniform} | ||
| import io.computenode.cyfra.dsl.struct.GStruct | ||
| import izumi.reflect.Tag | ||
|
|
||
| import java.nio.ByteBuffer | ||
|
|
||
| trait Allocation: | ||
| extension (buffer: GBinding[?]) | ||
| def read(bb: ByteBuffer, offset: Int = 0, length: Int = -1): Unit | ||
|
|
||
| def write(bb: ByteBuffer, offset: Int = 0, length: Int = -1): Unit | ||
|
|
||
| extension [Params, L <: Layout, RL <: Layout: LayoutStruct](execution: GExecution[Params, L, RL]) def execute(params: Params, layout: L): RL | ||
|
|
||
| extension (buffers: GBuffer.type) | ||
| def apply[T <: Value: {Tag, FromExpr}](size: Int): GBuffer[T] | ||
|
|
||
| def apply[T <: Value: {Tag, FromExpr}](buff: ByteBuffer): GBuffer[T] | ||
|
|
||
| extension (buffers: GUniform.type) | ||
| def apply[T <: Value: {Tag, FromExpr}](buff: ByteBuffer): GUniform[T] | ||
|
|
||
| def apply[T <: Value: {Tag, FromExpr}](): GUniform[T] | ||
7 changes: 7 additions & 0 deletions
7
cyfra-core/src/main/scala/io/computenode/cyfra/core/CyfraRuntime.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package io.computenode.cyfra.core | ||
|
|
||
| import io.computenode.cyfra.core.Allocation | ||
|
|
||
| trait CyfraRuntime: | ||
|
|
||
| def allocation(): Allocation |
47 changes: 47 additions & 0 deletions
47
cyfra-core/src/main/scala/io/computenode/cyfra/core/GBufferRegion.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package io.computenode.cyfra.core | ||
|
|
||
| import io.computenode.cyfra.core.Allocation | ||
| import io.computenode.cyfra.core.GProgram.BufferSizeSpec | ||
| import io.computenode.cyfra.core.layout.{Layout, LayoutStruct} | ||
| import io.computenode.cyfra.dsl.Value | ||
| import io.computenode.cyfra.dsl.Value.FromExpr | ||
| import io.computenode.cyfra.dsl.binding.GBuffer | ||
| import izumi.reflect.Tag | ||
|
|
||
| import java.nio.ByteBuffer | ||
|
|
||
| sealed trait GBufferRegion[ReqAlloc <: Layout: LayoutStruct, ResAlloc <: Layout: LayoutStruct]: | ||
MarconZet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val initAlloc: ReqAlloc | ||
|
|
||
| object GBufferRegion: | ||
|
|
||
| def allocate[Alloc <: Layout: LayoutStruct]: GBufferRegion[Alloc, Alloc] = | ||
| AllocRegion(summon[LayoutStruct[Alloc]].layoutRef) | ||
|
|
||
| case class AllocRegion[Alloc <: Layout: LayoutStruct](l: Alloc) extends GBufferRegion[Alloc, Alloc]: | ||
| val initAlloc: Alloc = l | ||
|
|
||
| case class MapRegion[ReqAlloc <: Layout: LayoutStruct, BodyAlloc <: Layout: LayoutStruct, ResAlloc <: Layout: LayoutStruct]( | ||
MarconZet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| reqRegion: GBufferRegion[ReqAlloc, BodyAlloc], | ||
| f: Allocation => BodyAlloc => ResAlloc, | ||
| ) extends GBufferRegion[ReqAlloc, ResAlloc]: | ||
| val initAlloc: ReqAlloc = reqRegion.initAlloc | ||
|
|
||
| extension [ReqAlloc <: Layout: LayoutStruct, ResAlloc <: Layout: LayoutStruct](region: GBufferRegion[ReqAlloc, ResAlloc]) | ||
| def map[NewAlloc <: Layout: LayoutStruct](f: Allocation ?=> ResAlloc => NewAlloc): GBufferRegion[ReqAlloc, NewAlloc] = | ||
| MapRegion(region, (alloc: Allocation) => (resAlloc: ResAlloc) => f(using alloc)(resAlloc)) | ||
|
|
||
| def runUnsafe(init: Allocation ?=> ReqAlloc, onDone: Allocation ?=> ResAlloc => Unit)(using cyfraRuntime: CyfraRuntime): Unit = | ||
| val allocation = cyfraRuntime.allocation() | ||
| init(using allocation) | ||
|
|
||
| // noinspection ScalaRedundantCast | ||
| val steps: Seq[Allocation => Layout => Layout] = Seq.unfold(region: GBufferRegion[?, ?]): | ||
| case _: AllocRegion[?] => None | ||
| case MapRegion(req, f) => | ||
| Some((f.asInstanceOf[Allocation => Layout => Layout], req)) | ||
|
|
||
| val bodyAlloc = steps.foldLeft[Layout](region.initAlloc): (acc, step) => | ||
| step(allocation)(acc) | ||
|
|
||
| onDone(using allocation)(bodyAlloc.asInstanceOf[ResAlloc]) | ||
62 changes: 62 additions & 0 deletions
62
cyfra-core/src/main/scala/io/computenode/cyfra/core/GExecution.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package io.computenode.cyfra.core | ||
|
|
||
| import io.computenode.cyfra.core.GExecution.* | ||
| import io.computenode.cyfra.core.archive.GContext | ||
| import io.computenode.cyfra.core.layout.* | ||
| import io.computenode.cyfra.dsl.binding.GBuffer | ||
| import io.computenode.cyfra.dsl.gio.GIO | ||
| import io.computenode.cyfra.dsl.struct.{GStruct, GStructSchema} | ||
| import io.computenode.cyfra.spirv.compilers.ExpressionCompiler.UniformStructRef | ||
| import izumi.reflect.Tag | ||
| import GExecution.* | ||
|
|
||
| trait GExecution[-Params, ExecLayout <: Layout, +ResLayout <: Layout]: | ||
|
|
||
| def flatMap[NRL <: Layout, NP <: Params](f: ResLayout => GExecution[NP, ExecLayout, NRL]): GExecution[NP, ExecLayout, NRL] = | ||
| FlatMap(this, (p, r) => f(r)) | ||
|
|
||
| def map[NRL <: Layout](f: ResLayout => NRL): GExecution[Params, ExecLayout, NRL] = | ||
| Map(this, f, identity, identity) | ||
|
|
||
| def contramap[NL <: Layout](f: NL => ExecLayout): GExecution[Params, NL, ResLayout] = | ||
| Map(this, identity, f, identity) | ||
|
|
||
| def contramapParams[NP](f: NP => Params): GExecution[NP, ExecLayout, ResLayout] = | ||
| Map(this, identity, identity, f) | ||
|
|
||
| def addProgram[ProgramParams, PP <: Params, ProgramLayout <: Layout, P <: GProgram[ProgramParams, ProgramLayout]]( | ||
| program: P, | ||
| )(mapParams: PP => ProgramParams, mapLayout: ExecLayout => ProgramLayout): GExecution[PP, ExecLayout, ResLayout] = | ||
| val adapted = program.contramapParams(mapParams).contramap(mapLayout) | ||
| flatMap(r => adapted.map(_ => r)) | ||
|
|
||
| object GExecution: | ||
|
|
||
| def apply[Params, L <: Layout]() = | ||
| Pure[Params, L, L]() | ||
|
|
||
| def forParams[Params, L <: Layout, RL <: Layout](f: Params => GExecution[Params, L, RL]): GExecution[Params, L, RL] = | ||
| FlatMap[Params, L, RL, RL](Pure[Params, L, RL](), (params: Params, _: RL) => f(params)) | ||
|
|
||
| case class Pure[Params, L <: Layout, RL <: Layout]() extends GExecution[Params, L, RL] | ||
|
|
||
| case class FlatMap[Params, L <: Layout, RL <: Layout, NRL <: Layout]( | ||
| execution: GExecution[Params, L, RL], | ||
| f: (Params, RL) => GExecution[Params, L, NRL], | ||
| ) extends GExecution[Params, L, NRL] | ||
|
|
||
| case class Map[P, NP, L <: Layout, NL <: Layout, RL <: Layout, NRL <: Layout]( | ||
| execution: GExecution[P, L, RL], | ||
| mapResult: RL => NRL, | ||
| contramapLayout: NL => L, | ||
| contramapParams: NP => P, | ||
| ) extends GExecution[NP, NL, NRL]: | ||
|
|
||
| override def map[NNRL <: Layout](f: NRL => NNRL): GExecution[NP, NL, NNRL] = | ||
| Map(execution, mapResult andThen f, contramapLayout, contramapParams) | ||
|
|
||
| override def contramapParams[NNP](f: NNP => NP): GExecution[NNP, NL, NRL] = | ||
| Map(execution, mapResult, contramapLayout, f andThen contramapParams) | ||
|
|
||
| override def contramap[NNL <: Layout](f: NNL => NL): GExecution[NP, NNL, NRL] = | ||
| Map(execution, mapResult, f andThen contramapLayout, contramapParams) |
70 changes: 70 additions & 0 deletions
70
cyfra-core/src/main/scala/io/computenode/cyfra/core/GProgram.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package io.computenode.cyfra.core | ||
|
|
||
| import io.computenode.cyfra.core.layout.LayoutStruct | ||
| import io.computenode.cyfra.dsl.gio.GIO | ||
| import io.computenode.cyfra.core.layout.Layout | ||
|
|
||
| import java.nio.ByteBuffer | ||
| import GProgram.* | ||
| import io.computenode.cyfra.dsl.{Expression, Value} | ||
| import io.computenode.cyfra.dsl.Value.{FromExpr, Int32} | ||
| import io.computenode.cyfra.dsl.binding.{GBinding, GBuffer, GUniform} | ||
| import io.computenode.cyfra.dsl.struct.GStruct | ||
| import io.computenode.cyfra.dsl.struct.GStruct.Empty | ||
| import izumi.reflect.Tag | ||
|
|
||
| sealed trait GProgram[Params, L <: Layout: LayoutStruct] extends GExecution[Params, L, L]: | ||
| val layout: InitProgramLayout => Params => L | ||
| val dispatch: (L, Params) => ProgramDispatch | ||
| val workgroupSize: WorkDimensions | ||
|
|
||
| object GProgram: | ||
|
|
||
| class GioProgram[Params, L <: Layout: LayoutStruct]( | ||
| val body: L => GIO[?], | ||
| val layout: InitProgramLayout => Params => L, | ||
| val dispatch: (L, Params) => ProgramDispatch, | ||
| val workgroupSize: WorkDimensions, | ||
| ) extends GProgram[Params, L]: | ||
| private[cyfra] def layoutStruct: LayoutStruct[L] = summon[LayoutStruct[L]] | ||
|
|
||
| class SpirvProgram[Params, L <: Layout: LayoutStruct]( | ||
| val code: ByteBuffer, | ||
| val layout: InitProgramLayout => Params => L, | ||
| val dispatch: (L, Params) => ProgramDispatch, | ||
| val workgroupSize: WorkDimensions, | ||
| ) extends GProgram[Params, L]: | ||
| private[cyfra] def layoutStruct: LayoutStruct[L] = summon[LayoutStruct[L]] | ||
|
|
||
| type WorkDimensions = (Int, Int, Int) | ||
|
|
||
| sealed trait ProgramDispatch | ||
MarconZet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| case class DynamicDispatch[L <: Layout](buffer: GBinding[?], offset: Int) extends ProgramDispatch | ||
|
|
||
| case class StaticDispatch(size: WorkDimensions) extends ProgramDispatch | ||
|
|
||
| private[cyfra] case class BufferSizeSpec[T <: Value: {Tag, FromExpr}](size: Int) extends GBuffer[T] | ||
|
|
||
| private[cyfra] case class ParamUniform[T <: GStruct[T]: {Tag, FromExpr}](value: T) extends GUniform[T] | ||
|
|
||
| private[cyfra] case class DynamicUniform[T <: GStruct[T]: {Tag, FromExpr}]() extends GUniform[T] | ||
|
|
||
| trait InitProgramLayout: | ||
| extension (buffers: GBuffer.type) | ||
| def apply[T <: Value: {Tag, FromExpr}](size: Int): GBuffer[T] = | ||
| BufferSizeSpec[T](size) | ||
|
|
||
| extension (uniforms: GUniform.type) | ||
| def apply[T <: GStruct[T]: {Tag, FromExpr}](value: T): GUniform[T] = | ||
| ParamUniform[T](value) | ||
|
|
||
| def apply[T <: GStruct[T]: {Tag, FromExpr}](): GUniform[T] = | ||
| DynamicUniform[T]() | ||
|
|
||
| def apply[Params, L <: Layout: LayoutStruct]( | ||
| layout: InitProgramLayout ?=> Params => L, | ||
| dispatch: (L, Params) => ProgramDispatch, | ||
| workgroupSize: WorkDimensions = (128, 1, 1), | ||
| )(body: L => GIO[?]): GProgram[Params, L] = | ||
| new GioProgram[Params, L](body, s => layout(using s), dispatch, workgroupSize) | ||
4 changes: 2 additions & 2 deletions
4
...omputenode/cyfra/runtime/Executable.scala → ...enode/cyfra/core/archive/Executable.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
...computenode/cyfra/runtime/GFunction.scala → ...tenode/cyfra/core/archive/GFunction.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
cyfra-core/src/main/scala/io/computenode/cyfra/core/archive/UniformContext.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package io.computenode.cyfra.core.archive | ||
|
|
||
| import io.computenode.cyfra.core.archive.UniformContext | ||
| import io.computenode.cyfra.dsl.struct.* | ||
| import io.computenode.cyfra.dsl.struct.GStruct.Empty | ||
| import izumi.reflect.Tag | ||
|
|
||
| class UniformContext[G <: GStruct[G]: {Tag, GStructSchema}](val uniform: G) | ||
|
|
||
| object UniformContext: | ||
| def withUniform[G <: GStruct[G]: {Tag, GStructSchema}, T](uniform: G)(fn: UniformContext[G] ?=> T): T = | ||
| fn(using UniformContext(uniform)) | ||
| given empty: UniformContext[Empty] = new UniformContext(Empty()) |
2 changes: 1 addition & 1 deletion
2
...putenode/cyfra/runtime/mem/FloatMem.scala → ...ode/cyfra/core/archive/mem/FloatMem.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...omputenode/cyfra/runtime/mem/IntMem.scala → ...enode/cyfra/core/archive/mem/IntMem.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mputenode/cyfra/runtime/mem/RamGMem.scala → ...node/cyfra/core/archive/mem/RamGMem.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...node/cyfra/runtime/mem/Vec4FloatMem.scala → ...cyfra/core/archive/mem/Vec4FloatMem.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
cyfra-core/src/main/scala/io/computenode/cyfra/core/binding/BufferRef.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package io.computenode.cyfra.core.binding | ||
|
|
||
| import io.computenode.cyfra.dsl.Value | ||
| import io.computenode.cyfra.dsl.Value.FromExpr | ||
| import io.computenode.cyfra.dsl.binding.GBuffer | ||
| import izumi.reflect.Tag | ||
| import izumi.reflect.macrortti.LightTypeTag | ||
|
|
||
| case class BufferRef[T <: Value: {Tag, FromExpr}](layoutOffset: Int, valueTag: Tag[T]) extends GBuffer[T] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.