Updated glslang as core dependency
This commit is contained in:
parent
03bea35fce
commit
1357549900
28 changed files with 119 additions and 217 deletions
|
|
@ -33,34 +33,6 @@ PYBIND11_MODULE(kp, m) {
|
|||
.value("storage", kp::Tensor::TensorTypes::eStorage, DOC(kp, Tensor, TensorTypes, eStorage))
|
||||
.export_values();
|
||||
|
||||
#if !defined(KOMPUTE_DISABLE_SHADER_UTILS) || !KOMPUTE_DISABLE_SHADER_UTILS
|
||||
py::class_<kp::Shader>(m, "Shader", "Shader class")
|
||||
.def_static("compile_source", [](
|
||||
const std::string& source,
|
||||
const std::string& entryPoint,
|
||||
const std::vector<std::pair<std::string,std::string>>& definitions) {
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSource(source, entryPoint, definitions);
|
||||
return py::bytes((const char*)spirv.data(), spirv.size() * sizeof(uint32_t));
|
||||
},
|
||||
DOC(kp, Shader, compileSource),
|
||||
py::arg("source"),
|
||||
py::arg("entryPoint") = "main",
|
||||
py::arg("definitions") = std::vector<std::pair<std::string,std::string>>() )
|
||||
.def_static("compile_sources", [](
|
||||
const std::vector<std::string>& source,
|
||||
const std::vector<std::string>& files,
|
||||
const std::string& entryPoint,
|
||||
const std::vector<std::pair<std::string,std::string>>& definitions) {
|
||||
std::vector<uint32_t> spirv = kp::Shader::compileSources(source, files, entryPoint, definitions);
|
||||
return py::bytes((const char*)spirv.data(), spirv.size() * sizeof(uint32_t));
|
||||
},
|
||||
DOC(kp, Shader, compileSources),
|
||||
py::arg("sources"),
|
||||
py::arg("files") = std::vector<std::string>(),
|
||||
py::arg("entryPoint") = "main",
|
||||
py::arg("definitions") = std::vector<std::pair<std::string,std::string>>() );
|
||||
#endif // KOMPUTE_DISABLE_SHADER_UTILS
|
||||
|
||||
py::class_<kp::OpBase, std::shared_ptr<kp::OpBase>>(m, "OpBase", DOC(kp, OpBase));
|
||||
|
||||
py::class_<kp::OpTensorSyncDevice, std::shared_ptr<kp::OpTensorSyncDevice>>(
|
||||
|
|
|
|||
|
|
@ -5,10 +5,13 @@ import numpy as np
|
|||
import logging
|
||||
import pyshader as ps
|
||||
|
||||
import pyshaderc
|
||||
|
||||
DIRNAME = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
kp_log = logging.getLogger("kp")
|
||||
|
||||
|
||||
def test_end_to_end():
|
||||
|
||||
mgr = kp.Manager()
|
||||
|
|
@ -52,7 +55,7 @@ def test_end_to_end():
|
|||
push_consts_a = [2]
|
||||
push_consts_b = [3]
|
||||
|
||||
algo = mgr.algorithm(params, kp.Shader.compile_source(shader), workgroup, spec_consts, push_consts_a)
|
||||
algo = mgr.algorithm(params, pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp"), workgroup, spec_consts, push_consts_a)
|
||||
|
||||
(mgr.sequence()
|
||||
.record(kp.OpTensorSyncDevice(params))
|
||||
|
|
@ -88,7 +91,7 @@ void main()
|
|||
}
|
||||
"""
|
||||
|
||||
spirv = kp.Shader.compile_source(shader)
|
||||
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
|
||||
|
||||
mgr = kp.Manager()
|
||||
|
||||
|
|
@ -108,6 +111,7 @@ void main()
|
|||
|
||||
assert tensor_out.data().tolist() == [2.0, 4.0, 6.0]
|
||||
|
||||
|
||||
def test_sequence():
|
||||
"""
|
||||
Test basic OpAlgoBase operation
|
||||
|
|
@ -127,7 +131,7 @@ def test_sequence():
|
|||
}
|
||||
"""
|
||||
|
||||
spirv = kp.Shader.compile_source(shader)
|
||||
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
|
||||
|
||||
mgr = kp.Manager(0)
|
||||
|
||||
|
|
@ -164,9 +168,10 @@ def test_sequence():
|
|||
assert tensor_in_b.is_init() == False
|
||||
assert tensor_out.is_init() == False
|
||||
|
||||
|
||||
def test_pushconsts():
|
||||
|
||||
spirv = kp.Shader.compile_source("""
|
||||
spirv = pyshaderc.compile_into_spirv("""
|
||||
#version 450
|
||||
layout(push_constant) uniform PushConstants {
|
||||
float x;
|
||||
|
|
@ -180,7 +185,7 @@ def test_pushconsts():
|
|||
pa[1] += pcs.y;
|
||||
pa[2] += pcs.z;
|
||||
}
|
||||
""")
|
||||
""".encode("utf-8"), "comp", "shader.comp")
|
||||
|
||||
mgr = kp.Manager()
|
||||
|
||||
|
|
@ -197,6 +202,7 @@ def test_pushconsts():
|
|||
|
||||
assert np.all(tensor.data() == np.array([0.4, 0.4, 0.4], dtype=np.float32))
|
||||
|
||||
|
||||
def test_workgroup():
|
||||
mgr = kp.Manager(0)
|
||||
|
||||
|
|
@ -227,6 +233,7 @@ def test_workgroup():
|
|||
assert np.all(tensor_a.data() == np.stack([np.arange(16)]*8, axis=1).ravel())
|
||||
assert np.all(tensor_b.data() == np.stack([np.arange(8)]*16, axis=0).ravel())
|
||||
|
||||
|
||||
def test_mgr_utils():
|
||||
mgr = kp.Manager()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import pyshader as ps
|
||||
import pyshaderc
|
||||
import os
|
||||
import pytest
|
||||
import kp
|
||||
|
|
@ -22,7 +23,7 @@ def test_type_float():
|
|||
}
|
||||
"""
|
||||
|
||||
spirv = kp.Shader.compile_source(shader)
|
||||
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
|
||||
|
||||
arr_in_a = np.array([123., 153., 231.], dtype=np.float32)
|
||||
arr_in_b = np.array([9482, 1208, 1238], dtype=np.float32)
|
||||
|
|
@ -61,7 +62,7 @@ def test_type_float_double_incorrect():
|
|||
}
|
||||
"""
|
||||
|
||||
spirv = kp.Shader.compile_source(shader)
|
||||
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
|
||||
|
||||
arr_in_a = np.array([123., 153., 231.], dtype=np.float32)
|
||||
arr_in_b = np.array([9482, 1208, 1238], dtype=np.uint32)
|
||||
|
|
@ -103,7 +104,7 @@ def test_type_double():
|
|||
}
|
||||
"""
|
||||
|
||||
spirv = kp.Shader.compile_source(shader)
|
||||
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
|
||||
|
||||
arr_in_a = np.array([123., 153., 231.], dtype=np.float64)
|
||||
arr_in_b = np.array([9482, 1208, 1238], dtype=np.float64)
|
||||
|
|
@ -143,7 +144,7 @@ def test_type_int():
|
|||
}
|
||||
"""
|
||||
|
||||
spirv = kp.Shader.compile_source(shader)
|
||||
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
|
||||
|
||||
arr_in_a = np.array([123, 153, 231], dtype=np.int32)
|
||||
arr_in_b = np.array([9482, 1208, 1238], dtype=np.int32)
|
||||
|
|
@ -183,7 +184,7 @@ def test_type_unsigned_int():
|
|||
}
|
||||
"""
|
||||
|
||||
spirv = kp.Shader.compile_source(shader)
|
||||
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
|
||||
|
||||
arr_in_a = np.array([123, 153, 231], dtype=np.uint32)
|
||||
arr_in_b = np.array([9482, 1208, 1238], dtype=np.uint32)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue