def test_memoryFlags(): """ Test that the returned memory flags meet the Vulkan speficiation. From the Vulkan specification: There must be at least one memory type with both the VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT and VK_MEMORY_PROPERTY_HOST_COHERENT_BIT bits set in its propertyFlags. There must be at least one memory type with the VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT bit set in its propertyFlags. """ session = ll.createSession() memFlags = session.getSupportedMemoryPropertyFlags() devFlagsFound = False hostFlagsFound = False for flags in memFlags: if ll.MemoryPropertyFlagBits.HostVisible in flags and ll.MemoryPropertyFlagBits.HostCoherent in flags: hostFlagsFound = True if ll.MemoryPropertyFlagBits.DeviceLocal in flags: devFlagsFound = True assert (hostFlagsFound and devFlagsFound)
def test_creation(): session = ll.createSession() mem = session.createMemory(ll.MemoryPropertyFlagBits.DeviceLocal) width = 640 height = 480 flags = [ ll.ImageUsageFlagBits.TransferSrc, ll.ImageUsageFlagBits.TransferDst, ll.ImageUsageFlagBits.Storage, ll.ImageUsageFlagBits.Sampled ] channelType = ll.ChannelType.Uint8 img = mem.createImage([height, width, 1], channelType, flags) assert (img.width == width) assert (img.height == height) assert (img.depth == 1) assert (img.channels == 1) assert (img.channelType == channelType) assert (img.shape == (1, height, width, 1)) assert (len(flags) == len(img.usageFlags)) for f in img.usageFlags: assert (f in flags)
def test_compile(): session = ll.createSession() memory = session.createMemory() shaderCode = """ #version 450 // default values for the local group size as well as // indexes for the specialization constants to override them. layout ( local_size_x_id = 1, local_size_x = 1, local_size_y_id = 2, local_size_y = 1, local_size_z_id = 3, local_size_z = 1 ) in; layout(binding = 0) buffer in0 {int A[]; }; layout(binding = 1) buffer in1 {int B[]; }; layout(binding = 2) buffer out0 {int C[]; }; void main() { const uint index = gl_GlobalInvocationID.x; C[index] = A[index] + B[index]; } """ localLength = 32 gridLength = 4 length = gridLength * localLength dtype = np.int32 A_host = np.arange(0, length, dtype=dtype) B_host = np.arange(0, length, dtype=dtype) C_host = A_host + B_host A = memory.createBufferFromHost(A_host) B = memory.createBufferFromHost(B_host) C = memory.createBufferLike(A_host) ports = [ ll.PortDescriptor(0, 'in_A', ll.PortDirection.In, ll.PortType.Buffer), ll.PortDescriptor(1, 'in_B', ll.PortDirection.In, ll.PortType.Buffer), ll.PortDescriptor(2, 'out_C', ll.PortDirection.Out, ll.PortType.Buffer) ] node = session.compileComputeNode(ports, shaderCode, 'main', localSize=(localLength, 1, 1), gridSize=(gridLength, 1, 1)) node.bind('in_A', A) node.bind('in_B', B) node.bind('out_C', C) node.init() node.run() C_copy = C.toHost(dtype=dtype) assert((C_copy == C_host).all())
def test_fromHost(): session = ll.createSession() mem = session.createMemory() dtype = np.uint8 arr = np.arange(0, 64, dtype=dtype) buf = mem.createBufferFromHost(arr) copy = buf.toHost(dtype=dtype) for i in range(len(arr)): assert (arr[i] == copy[i])
def test_load_library(): import lluvia as ll print("LL_PATH: ", ll.__path__) session = ll.createSession() session.loadLibrary('lluvia/cpp/core/test/nodes/test_node_library.zip') desc = session.createComputeNodeDescriptor('nodes/Assign') assert (desc != None) program = session.getProgram('nodes/Assign') assert (program != None) node = session.createComputeNode("nodes/Assign") assert (node != None)
def test_creation(): session = ll.createSession() mem = session.createMemory(ll.MemoryPropertyFlagBits.DeviceLocal) size = 512 # some flags different to the default values of mem.createBuffer() flags = [ ll.BufferUsageFlagBits.IndexBuffer, ll.BufferUsageFlagBits.UniformBuffer ] buf = mem.createBuffer(size, flags) assert (buf.size == size) assert (len(flags) == len(buf.usageFlags)) # check that all flags have the correct value for f in buf.usageFlags: assert (f in flags)
def test_imageFromHost(): img = imageio.imread('../resources/autumn.jpg') imgRGBA = np.zeros(img.shape[:-1] + tuple([4]), dtype=img.dtype) imgRGBA[..., :3] = img session = ll.createSession() mem = session.createMemory() devImg = mem.createImageFromHost(imgRGBA) assert (devImg.depth == 1) assert (devImg.height == imgRGBA.shape[0]) assert (devImg.width == imgRGBA.shape[1]) assert (devImg.channels == imgRGBA.shape[2]) hostImg = devImg.toHost() assert (hostImg.shape == imgRGBA.shape) # pixel-wise check assert ((hostImg[:] == imgRGBA[:]).all())
def test_incorrectSize(): session = ll.createSession() mem = session.createMemory(ll.MemoryPropertyFlagBits.DeviceLocal) width = 640 height = 480 depth = 10 channels = 4 channelType = ll.ChannelType.Uint8 # wrong shapes that should raise ValueError shapes = [(0, height, width, channels), (depth, 0, width, channels), (depth, height, 0, channels), (depth, height, width, 0), (depth, height, height, 5)] with pytest.raises(ValueError): for shape in shapes: img = mem.createImage(shape, channelType)
def test_session(): session = ll.createSession()
def test_session(): import lluvia as ll ll.createSession()